exo-jcr SVN: r3609 - in ws/branches/2.1.x/exo.ws.rest.ext/src: test/java/org/exoplatform/services/rest/ext/filter and 1 other directory.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-07 08:33:22 -0500 (Tue, 07 Dec 2010)
New Revision: 3609
Added:
ws/branches/2.1.x/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java
Modified:
ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProvider.java
Log:
JCR-1539: from now filteredReader is used instead of reader for parsing request XML body
Modified: ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProvider.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProvider.java 2010-12-07 13:30:27 UTC (rev 3608)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/provider/HierarchicalPropertyEntityProvider.java 2010-12-07 13:33:22 UTC (rev 3609)
@@ -29,16 +29,18 @@
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.Stack;
+import java.util.LinkedList;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.xml.namespace.QName;
+import javax.xml.stream.EventFilter;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Characters;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.TransformerException;
@@ -77,33 +79,40 @@
WebApplicationException
{
HierarchicalProperty rootProperty = null;
- Stack<HierarchicalProperty> curProperty = new Stack<HierarchicalProperty>();
+ LinkedList<HierarchicalProperty> curProperty = new LinkedList<HierarchicalProperty>();
try
{
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(entityStream);
- while (reader.hasNext())
+ XMLEventReader fReader = factory.createFilteredReader(reader, new EventFilter()
{
- XMLEvent event = reader.nextEvent();
+ public boolean accept(XMLEvent event)
+ {
+ return !(event.isCharacters() && ((Characters)event).isWhiteSpace());
+ }
+ });
+ while (fReader.hasNext())
+ {
+ XMLEvent event = fReader.nextEvent();
switch (event.getEventType())
{
case XMLEvent.START_ELEMENT :
StartElement element = event.asStartElement();
QName name = element.getName();
HierarchicalProperty prop = new HierarchicalProperty(name);
- if (!curProperty.empty())
- curProperty.peek().addChild(prop);
+ if (!curProperty.isEmpty())
+ curProperty.getLast().addChild(prop);
else
rootProperty = prop;
- curProperty.push(prop);
+ curProperty.addLast(prop);
break;
case XMLEvent.END_ELEMENT :
- curProperty.pop();
+ curProperty.removeLast();
break;
case XMLEvent.CHARACTERS :
String chars = event.asCharacters().getData();
- curProperty.peek().setValue(chars);
+ curProperty.getLast().setValue(chars);
break;
default :
break;
@@ -119,9 +128,23 @@
catch (XMLStreamException e)
{
if (LOG.isDebugEnabled())
- e.printStackTrace();
+ LOG.debug("An XMLStreamException occurs", e);
return null;
}
+ catch (RuntimeException re)
+ {
+ String reName = re.getClass().getName();
+ if (reName.equals("com.ctc.wstx.exc.WstxLazyException"))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.error(re.getMessage(), re);
+ return null;
+ }
+ else
+ {
+ throw re;
+ }
+ }
}
/**
Added: ws/branches/2.1.x/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java (rev 0)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/test/java/org/exoplatform/services/rest/ext/filter/HierarchicalPropertyEntityProviderTest.java 2010-12-07 13:33:22 UTC (rev 3609)
@@ -0,0 +1,21 @@
+package org.exoplatform.services.rest.ext.filter;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.common.util.HierarchicalProperty;
+import org.exoplatform.services.rest.ext.provider.HierarchicalPropertyEntityProvider;
+
+import java.io.ByteArrayInputStream;
+
+public class HierarchicalPropertyEntityProviderTest extends TestCase
+{
+ public void testRequestBodyXMLParsing() throws Exception
+ {
+ String s = "\n<root>\n <l1>\n\t<l2>hel\nlo</l2>\n </l1> \n</root>\n";
+ System.out.println(s);
+ HierarchicalProperty hp =
+ new HierarchicalPropertyEntityProvider().readFrom(HierarchicalProperty.class, null, null, null, null,
+ new ByteArrayInputStream(s.getBytes()));
+ assertTrue(hp.getChild(0).getChild(0).getValue().equals("hel\nlo"));
+ }
+}
\ No newline at end of file
15 years, 5 months
exo-jcr SVN: r3608 - in jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command: dasl and 4 other directories.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-07 08:30:27 -0500 (Tue, 07 Dec 2010)
New Revision: 3608
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/dasl/SearchResultResponseEntity.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/report/VersionTreeResponseEntity.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/order/OrderPatchResponseEntity.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindResponseEntity.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/proppatch/PropPatchResponseEntity.java
Log:
JCR-1539: from now default namespace is removed from response XML body creation
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -209,7 +209,6 @@
XMLStreamWriter xmlStreamWriter =
XMLOutputFactory.newInstance().createXMLStreamWriter(stream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(nsContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/dasl/SearchResultResponseEntity.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/dasl/SearchResultResponseEntity.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/dasl/SearchResultResponseEntity.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -118,7 +118,6 @@
XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(nsContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("D", "multistatus", "DAV:");
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/report/VersionTreeResponseEntity.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/report/VersionTreeResponseEntity.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/report/VersionTreeResponseEntity.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -101,7 +101,6 @@
this.xmlStreamWriter =
XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(namespaceContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("D", "multistatus", "DAV:");
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/order/OrderPatchResponseEntity.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/order/OrderPatchResponseEntity.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/order/OrderPatchResponseEntity.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -96,7 +96,6 @@
XMLStreamWriter xmlStreamWriter =
XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(nsContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("D", "multistatus", "DAV:");
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindResponseEntity.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindResponseEntity.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindResponseEntity.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -132,7 +132,6 @@
this.xmlStreamWriter =
XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(namespaceContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("D", "multistatus", "DAV:");
Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/proppatch/PropPatchResponseEntity.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/proppatch/PropPatchResponseEntity.java 2010-12-07 13:29:10 UTC (rev 3607)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/proppatch/PropPatchResponseEntity.java 2010-12-07 13:30:27 UTC (rev 3608)
@@ -146,7 +146,6 @@
XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, Constants.DEFAULT_ENCODING);
xmlStreamWriter.setNamespaceContext(nsContext);
- xmlStreamWriter.setDefaultNamespace("DAV:");
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("D", "multistatus", "DAV:");
15 years, 5 months
exo-jcr SVN: r3607 - in jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr: impl/core and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-07 08:29:10 -0500 (Tue, 07 Dec 2010)
New Revision: 3607
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java
Log:
EXOJCR-1078: test RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-07 13:24:01 UTC (rev 3606)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-07 13:29:10 UTC (rev 3607)
@@ -32,10 +32,15 @@
import java.io.File;
import java.net.URL;
+import java.sql.Connection;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
* @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
@@ -153,4 +158,61 @@
}
}
+ public void testRDBMSInitializerRestoreTables() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws1");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws1", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+
+ for (WorkspaceEntry workspaceEntry : repositoryService.getRepository("db1").getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (workspaceEntry.getName().equals("ws1"))
+ {
+ String newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
+ String newIndexPath = "target/temp/index/" + IdGenerator.generate();
+
+ String dsName = helper.getNewDataSource("");
+ DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+
+ Connection conn = ds.getConnection();
+ Statement st = conn.createStatement();
+ st.execute("CREATE TABLE JCR_MITEM(ID VARCHAR(96) NOT NULL,PARENT_ID VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED INTEGER,CONSTRAINT JCR_PK_MITEM PRIMARY KEY(ID))");
+ conn.commit();
+
+ // set the initializer
+ WorkspaceEntry newEntry =
+ helper.getNewWs("ws1", true, dsName, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
+ workspaceEntry.getContainer().getValueStorages());
+
+ WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
+ wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
+
+ List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
+ wieParams.add(new SimpleParameterEntry(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, new File(url
+ .getFile()).getParent()));
+
+ wiEntry.setParameters(wieParams);
+
+ newEntry.setInitializer(wiEntry);
+
+ RdbmsWorkspaceInitializerWrapper initializer =
+ new RdbmsWorkspaceInitializerWrapper(newEntry,
+ repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
+ (ValueFactoryImpl)valueFactory, null);
+
+ initializer.restoreTables(conn, "JCR_MITEM");
+ }
+ }
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java 2010-12-07 13:24:01 UTC (rev 3606)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java 2010-12-07 13:29:10 UTC (rev 3607)
@@ -27,6 +27,8 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -62,4 +64,11 @@
{
super.restoreIndex();
}
+
+ public void restoreTables(Connection jdbcConn, String tableName) throws RepositoryConfigurationException,
+ IOException, SQLException
+ {
+ super.restoreTable(jdbcConn, tableName);
+ }
+
}
15 years, 5 months
exo-jcr SVN: r3606 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-07 08:24:01 -0500 (Tue, 07 Dec 2010)
New Revision: 3606
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
Log:
EXOJCR-1078: implementation RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java 2010-12-07 11:10:27 UTC (rev 3605)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java 2010-12-07 13:24:01 UTC (rev 3606)
@@ -44,7 +44,6 @@
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -120,6 +119,9 @@
*/
public static final byte LONG_LEN = 3;
+ /**
+ * List of temporary files.
+ */
protected List<File> spoolFileList = new ArrayList<File>();
/**
@@ -503,10 +505,12 @@
try
{
contentReader =
- new ObjectReaderImpl(new FileInputStream(new File(restorePath, tableName + CONTENT_FILE_SUFFIX)));
+ new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(restorePath, tableName
+ + CONTENT_FILE_SUFFIX)));
contentLenReader =
- new ObjectReaderImpl(new FileInputStream(new File(restorePath, tableName + CONTENT_LEN_FILE_SUFFIX)));
+ new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(restorePath, tableName
+ + CONTENT_LEN_FILE_SUFFIX)));
int columnCount = contentReader.readInt();
int[] columnType = new int[columnCount];
@@ -586,7 +590,6 @@
}
else
{
- // for Postgres
insertNode.setBinaryStream(i + 1, stream, (int)len);
}
}
15 years, 5 months
exo-jcr SVN: r3605 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-07 06:10:27 -0500 (Tue, 07 Dec 2010)
New Revision: 3605
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
Log:
EXOJCR-1078: implementation RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-07 11:10:03 UTC (rev 3604)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-07 11:10:27 UTC (rev 3605)
@@ -75,26 +75,6 @@
protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.FullBackupJob");
/**
- * Content is absent.
- */
- public static final byte NULL_LEN = 0;
-
- /**
- * Content length value has byte type.
- */
- public static final byte BYTE_LEN = 1;
-
- /**
- * Content length value has integer type.
- */
- public static final byte INT_LEN = 2;
-
- /**
- * Content length value has long type.
- */
- public static final byte LONG_LEN = 3;
-
- /**
* Indicates the way to get value thru getBinaryStream() method.
*/
public static final int GET_BINARY_STREAM_METHOD = 0;
@@ -424,7 +404,7 @@
InputStream value = getInputStream(rs, i + 1, getValueMethod);
if (value == null)
{
- contentLenWriter.writeByte(NULL_LEN);
+ contentLenWriter.writeByte(RdbmsWorkspaceInitializer.NULL_LEN);
}
else
{
@@ -492,17 +472,17 @@
{
if (len < Byte.MAX_VALUE)
{
- out.writeByte(BYTE_LEN);
+ out.writeByte(RdbmsWorkspaceInitializer.BYTE_LEN);
out.writeByte((byte)len);
}
else if (len < Integer.MAX_VALUE)
{
- out.writeByte(INT_LEN);
+ out.writeByte(RdbmsWorkspaceInitializer.INT_LEN);
out.writeInt((int)len);
}
else
{
- out.writeByte(LONG_LEN);
+ out.writeByte(RdbmsWorkspaceInitializer.LONG_LEN);
out.writeLong(len);
}
}
15 years, 5 months
exo-jcr SVN: r3604 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-07 06:10:03 -0500 (Tue, 07 Dec 2010)
New Revision: 3604
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
Log:
EXOJCR-1078: implementation RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-06 14:34:57 UTC (rev 3603)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-07 11:10:03 UTC (rev 3604)
@@ -19,7 +19,6 @@
package org.exoplatform.services.jcr.impl.core;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.access.AccessManager;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
@@ -75,13 +74,6 @@
{
protected final String restoreDir;
- private FileCleaner fileCleaner;
-
- /**
- * Temporary directory;
- */
- private final File tempDir;
-
public BackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
@@ -90,8 +82,6 @@
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
accessManager);
- this.fileCleaner = valueFactory.getFileCleaner();
-
restoreDir = restorePath;
String fullBackupPath = getFullBackupPath();
@@ -104,8 +94,6 @@
{
restorePath = fullBackupPath;
}
-
- this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
@Override
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java 2010-12-06 14:34:57 UTC (rev 3603)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java 2010-12-07 11:10:03 UTC (rev 3604)
@@ -45,7 +45,6 @@
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -53,9 +52,10 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.Statement;
import java.sql.Types;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -101,6 +101,28 @@
public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
/**
+ * Content is absent.
+ */
+ public static final byte NULL_LEN = 0;
+
+ /**
+ * Content length value has byte type.
+ */
+ public static final byte BYTE_LEN = 1;
+
+ /**
+ * Content length value has integer type.
+ */
+ public static final byte INT_LEN = 2;
+
+ /**
+ * Content length value has long type.
+ */
+ public static final byte LONG_LEN = 3;
+
+ protected List<File> spoolFileList = new ArrayList<File>();
+
+ /**
* Constructor RdbmsWorkspaceInitializer.
*/
public RdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
@@ -125,6 +147,7 @@
Connection jdbcConn = null;
Integer transactionIsolation = null;
+ Statement st = null;
try
{
long start = System.currentTimeMillis();
@@ -163,6 +186,19 @@
transactionIsolation = jdbcConn.getTransactionIsolation();
jdbcConn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ jdbcConn.setAutoCommit(false);
+
+ // restore JCR data
+ String[] tables;
+ if (Boolean.parseBoolean(multiDb))
+ {
+ tables = new String[]{"JCR_MITEM", "JCR_MVALUE", "JCR_MREF"};
+ }
+ else
+ {
+ tables = new String[]{"JCR_SITEM", "JCR_SVALUE", "JCR_SREF"};
+ }
+
// resolve constraint name depends on database
String constraintName;
if (dbDialect.equals(DBConstants.DB_DIALECT_DB2) || dbDialect.equals(DBConstants.DB_DIALECT_DB2V8))
@@ -173,10 +209,41 @@
{
constraintName = "JCR_FK_" + (Boolean.parseBoolean(multiDb) ? "M" : "S") + "ITEM_PARENT";
}
+ String constraint =
+ "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES " + tables[0] + "(ID)";
- // restore from full backup
- // TODO
+ for (String table : tables)
+ {
+ if (table.equals("JCR_MITEM") || table.equals("JCR_SITEM"))
+ {
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + table + " DROP CONSTRAINT " + constraintName);
+ jdbcConn.commit();
+ restoreTable(jdbcConn, table);
+
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + table + " ADD CONSTRAINT " + constraint);
+ jdbcConn.commit();
+ }
+ else
+ {
+ restoreTable(jdbcConn, table);
+ }
+ }
+
+ // restore LOCK data
+ tables =
+ new String[]{"JCR_LOCK_" + workspaceName.toUpperCase(), "JCR_LOCK_" + workspaceName.toUpperCase() + "_D"};
+
+ for (String table : tables)
+ {
+ if (PrivilegedFileHelper.exists(new File(restorePath, table + CONTENT_FILE_SUFFIX)))
+ {
+ restoreTable(jdbcConn, table);
+ }
+ }
+
restoreValueStorage();
restoreIndex();
@@ -205,10 +272,45 @@
}
catch (SQLException e)
{
- throw new RepositoryException(e);
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.rollback();
+ }
+ catch (SQLException e1)
+ {
+ log.error("Rollback error", e1);
+ }
+ }
+
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new RepositoryException(msg, e);
}
finally
{
+ if (st != null)
+ {
+ try
+ {
+ st.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
if (jdbcConn != null)
{
try
@@ -326,39 +428,6 @@
}
}
- public static void restore(Properties props)
- {
-// File targetDir = new File(props.getProperty("targetdir"));
- //
- // File sitem = new File(targetDir, "jcr_sitem.dump");
- // sitem.exists();
- //
- // Statement st = dbConn.createStatement();
- // st.execute("ALTER TABLE JCR_SITEM DROP CONSTRAINT JCR_FK_SITEM_PARENT");
- // dbConn.commit();
- //
- // restoreTable(dbConn, sitem);
- //
- // st = dbConn.createStatement();
- // st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
- // dbConn.commit();
- //
- // for (File dumpFile : targetDir.listFiles())
- // {
- // if (dumpFile.getName().contains(".dump") && !dumpFile.getName().contains("jcr_sitem"))
- // {
- // restoreTable(dbConn, dumpFile);
- // }
- // }
- //
- // dbConn.close();
- //
- // copyDirectory(new File(targetDir, "values"), new File(props.getProperty("valuestoragedir")));
- // copyDirectory(new File(targetDir, "index"), new File(props.getProperty("indexdir")));
- // return;
-
- }
-
/**
* Copy directory.
*
@@ -419,134 +488,191 @@
}
}
- private static void restoreTable(Connection dbConn, File dumpFile)
+ /**
+ * Restore table.
+ */
+ protected void restoreTable(Connection jdbcConn, String tableName) throws IOException, SQLException
{
- String INSERT_NODE = null;
+ String insertNodeQuery = null;
- ObjectReader dump = null;
- ObjectReader leng = null;
+ ObjectReader contentReader = null;
+ ObjectReader contentLenReader = null;
+
+ PreparedStatement insertNode = null;
+
try
{
- dbConn.setAutoCommit(false);
+ contentReader =
+ new ObjectReaderImpl(new FileInputStream(new File(restorePath, tableName + CONTENT_FILE_SUFFIX)));
- dump = new ObjectReaderImpl(new FileInputStream(dumpFile));
- String tableName = dump.readString();
- int columnCount = dump.readInt();
+ contentLenReader =
+ new ObjectReaderImpl(new FileInputStream(new File(restorePath, tableName + CONTENT_LEN_FILE_SUFFIX)));
+ int columnCount = contentReader.readInt();
int[] columnType = new int[columnCount];
+
for (int i = 0; i < columnCount; i++)
{
- columnType[i] = dump.readInt();
+ columnType[i] = contentReader.readInt();
}
- leng = new ObjectReaderImpl(new FileInputStream(new File(dumpFile.getParentFile(), tableName + ".leng")));
-
for (int i = 0; i < columnCount; i++)
{
if (i == 0)
{
- INSERT_NODE = "INSERT INTO " + tableName + " VALUES(?";
+ insertNodeQuery = "INSERT INTO " + tableName + " VALUES(?";
}
else
{
- INSERT_NODE += ",?";
+ insertNodeQuery += ",?";
}
+
if (i == columnCount - 1)
{
- INSERT_NODE += ")";
+ insertNodeQuery += ")";
}
}
- PreparedStatement insertNode = dbConn.prepareStatement(INSERT_NODE);
- while (true)
+ insertNode = jdbcConn.prepareStatement(insertNodeQuery);
+ outer : while (true)
{
- try
+ for (int i = 0; i < columnCount; i++)
{
- for (int i = 0; i < columnCount; i++)
+ long len;
+ try
{
- long len = leng.readLong();
- if (len >= 0)
+ len = readCompressedContentLen(contentLenReader);
+ }
+ catch (EOFException e)
+ {
+ if (i == 0)
{
- InputStream stream = spoolInputStream(dump, len);
- if (columnType[i] == Types.INTEGER || columnType[i] == Types.BIGINT)
+ // content length file is empty check content file
+ try
{
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String p = new String(readBuffer);
- int l = Integer.parseInt(p);
-
- insertNode.setLong(i + 1, l);
+ contentReader.readByte();
}
- else if (columnType[i] == Types.BOOLEAN || columnType[i] == Types.BIT)
+ catch (EOFException e1)
{
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String p = new String(readBuffer);
- insertNode.setBoolean(i + 1, p.equals("t"));
+ break outer;
}
- else
- {
- // for Postgres
- insertNode.setBinaryStream(i + 1, stream, (int)len);
- }
}
+
+ throw new IOException("Content length file is empty but content still present", e);
+ }
+
+ if (len != NULL_LEN)
+ {
+ InputStream stream = spoolInputStream(contentReader, len);
+
+ if (columnType[i] == Types.INTEGER || columnType[i] == Types.BIGINT
+ || columnType[i] == Types.SMALLINT || columnType[i] == Types.TINYINT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String value = new String(readBuffer, Constants.DEFAULT_ENCODING);
+ insertNode.setLong(i + 1, Integer.parseInt(value));
+ }
+ else if (columnType[i] == Types.BOOLEAN || columnType[i] == Types.BIT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String value = new String(readBuffer);
+ insertNode.setBoolean(i + 1, value.equals("t"));
+ }
else
{
- insertNode.setNull(i + 1, columnType[i]);
+ // for Postgres
+ insertNode.setBinaryStream(i + 1, stream, (int)len);
}
}
- // insertNode.executeUpdate();
- insertNode.addBatch();
+ else
+ {
+ insertNode.setNull(i + 1, columnType[i]);
+ }
}
- catch (EOFException e)
- {
- break;
- }
+ insertNode.addBatch();
}
+
insertNode.executeBatch();
-
- insertNode.close();
-
- dump.close();
- leng.close();
-
- dbConn.commit();
+ jdbcConn.commit();
}
- catch (Exception e)
+ finally
{
- e.printStackTrace();
- try
+ if (contentReader != null)
{
- dbConn.rollback();
+ contentReader.close();
}
- catch (SQLException e1)
+
+ if (contentLenReader != null)
{
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ contentLenReader.close();
}
+
+ if (insertNode != null)
+ {
+ insertNode.close();
+ }
+
+ // delete all temporary files
+ for (File file : spoolFileList)
+ {
+ if (!PrivilegedFileHelper.delete(file))
+ {
+ fileCleaner.addFile(file);
+ }
+ }
}
}
- static public InputStream spoolInputStream(ObjectReader in, long maxLen) throws IOException
+ /**
+ * Write content length in output.
+ */
+ private long readCompressedContentLen(ObjectReader in) throws IOException
{
+ byte lenType = in.readByte();
+
+ if (lenType == NULL_LEN)
+ {
+ return lenType;
+ }
+ else if (lenType == BYTE_LEN)
+ {
+ return in.readByte();
+ }
+ else if (lenType == INT_LEN)
+ {
+ return in.readInt();
+ }
+ else
+ {
+ return in.readLong();
+ }
+ }
+
+ /**
+ * Spool input stream.
+ */
+ private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
+ {
byte[] buffer = new byte[0];
byte[] tmpBuff;
- long len = 0;
- File spoolFile = null;
+ long readLen = 0;
+ File sf = null;
OutputStream sfout = null;
try
{
while (true)
{
- int needToRead = maxLen - len > 2048 ? 2048 : (int)(maxLen - len);
+ int needToRead = contentLen - readLen > 2048 ? 2048 : (int)(contentLen - readLen);
tmpBuff = new byte[needToRead];
- if (needToRead <= 0)
+ if (needToRead == 0)
{
break;
}
@@ -557,10 +683,10 @@
{
sfout.write(tmpBuff);
}
- else if (len + needToRead > 200 * 1024)
+ else if (readLen + needToRead > maxBufferSize)
{
- spoolFile = File.createTempFile("swapFile", ".tmp");
- sfout = new FileOutputStream(spoolFile);
+ sf = PrivilegedFileHelper.createTempFile("jcrvd", null, tempDir);
+ sfout = PrivilegedFileHelper.fileOutputStream(sf);
sfout.write(buffer);
sfout.write(tmpBuff);
@@ -569,13 +695,13 @@
else
{
// reallocate new buffer and spool old buffer contents
- byte[] newBuffer = new byte[(int)(len + needToRead)];
- System.arraycopy(buffer, 0, newBuffer, 0, (int)len);
- System.arraycopy(tmpBuff, 0, newBuffer, (int)len, needToRead);
+ byte[] newBuffer = new byte[(int)(readLen + needToRead)];
+ System.arraycopy(buffer, 0, newBuffer, 0, (int)readLen);
+ System.arraycopy(tmpBuff, 0, newBuffer, (int)readLen, needToRead);
buffer = newBuffer;
}
- len += needToRead;
+ readLen += needToRead;
}
if (buffer != null)
@@ -584,13 +710,20 @@
}
else
{
- return new FileInputStream(spoolFile);
+ return PrivilegedFileHelper.fileInputStream(sf);
}
}
finally
{
if (sfout != null)
+ {
sfout.close();
+ }
+
+ if (sf != null)
+ {
+ spoolFileList.add(sf);
+ }
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-06 14:34:57 UTC (rev 3603)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-07 11:10:03 UTC (rev 3604)
@@ -105,16 +105,16 @@
private final LocationFactory locationFactory;
- private final int maxBufferSize;
+ protected final int maxBufferSize;
/**
* Cleaner should be started! .
*/
- private final FileCleaner fileCleaner;
+ protected final FileCleaner fileCleaner;
protected String restorePath;
- private final File tempDir;
+ protected final File tempDir;
protected class TempOutputStream extends ByteArrayOutputStream
{
15 years, 5 months
exo-jcr SVN: r3603 - in jcr/trunk/exo.jcr.component.ext: src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms and 5 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-06 09:34:57 -0500 (Mon, 06 Dec 2010)
New Revision: 3603
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java
Removed:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
Modified:
jcr/trunk/exo.jcr.component.ext/pom.xml
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
Log:
EXOJCR-1078: test RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-06 14:25:34 UTC (rev 3602)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-06 14:34:57 UTC (rev 3603)
@@ -185,12 +185,13 @@
<include>**/replication/*.java</include>
<include>**/replication/external/*.java</include>
<include>**/replication/async/**/*.java</include>
- <include>**/backup/TestBackupManager.java</include>
- <include>**/backup/TestFileNameProduser.java</include>
- <include>**/**/TestFullBackupJob.java</include>
+ <include>**/backup/*.java</include>
</includes>
<excludes>
<exclude>**/BaseStandaloneTest.java</exclude>
+ <exclude>**/backup/AbstractBackupTestCase.java</exclude>
+ <exclude>**/backup/TestBackupScheduler.java</exclude>
+ <exclude>**/backup/TestBackupRestart.java</exclude>
<exclude>**/replication/*.java</exclude>
<exclude>**/replication/external/*.java</exclude>
<exclude>**/replication/external/BaseTestCaseChecker.java</exclude>
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-06 14:25:34 UTC (rev 3602)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -31,6 +31,7 @@
import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.RdbmsWorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
@@ -74,31 +75,6 @@
protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.FullBackupJob");
/**
- * Index directory in full backup storage.
- */
- public static final String INDEX_DIR = "index";
-
- /**
- * System index directory in full backup storage.
- */
- public static final String SYSTEM_INDEX_DIR = INDEX_DIR + "_" + SystemSearchManager.INDEX_DIR_SUFFIX;
-
- /**
- * Value storage directory in full backup storage.
- */
- public static final String VALUE_STORAGE_DIR = "values";
-
- /**
- * Suffix for content file.
- */
- public static final String CONTENT_FILE_SUFFIX = ".dump";
-
- /**
- * Suffix for content length file.
- */
- public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
-
- /**
* Content is absent.
*/
public static final byte NULL_LEN = 0;
@@ -200,40 +176,37 @@
+ workspaceName);
}
+ String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+ if (multiDb == null)
+ {
+ throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
+ + " parameter not found in workspace " + workspaceName + " configuration");
+ }
+
final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
if (ds == null)
{
throw new NameNotFoundException("Data source " + dsName + " not found");
}
- jdbcConn =
- SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ jdbcConn = SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
{
- public Connection run() throws Exception
- {
- return ds.getConnection();
+ return ds.getConnection();
- }
- });
-
+ }
+ });
+
transactionIsolation = jdbcConn.getTransactionIsolation();
jdbcConn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
- {
- throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
- + " parameter not found in workspace " + workspaceName + " configuration");
- }
-
// dump JCR data
String[][] scripts;
if (Boolean.parseBoolean(multiDb))
{
scripts =
- new String[][]{
- {"JCR_MVALUE", "select * from JCR_MVALUE"},
- {"JCR_MREF", "select * from JCR_MREF"},
+ new String[][]{{"JCR_MVALUE", "select * from JCR_MVALUE"}, {"JCR_MREF", "select * from JCR_MREF"},
{"JCR_MITEM", "select * from JCR_MITEM"}};
}
else
@@ -269,62 +242,10 @@
{
dumpTable(jdbcConn, script[0], script[1]);
}
- else
- {
- log.warn("Table " + script[0] + " doesn't exist");
- }
}
- // copy value storage directory
- if (workspaceEntry.getContainer().getValueStorages() != null)
- {
- for (ValueStorageEntry valueStorage : workspaceEntry.getContainer().getValueStorages())
- {
- File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
- if (!PrivilegedFileHelper.exists(srcDir))
- {
- log.warn("Can't not backup value storage. Directory " + srcDir.getName() + " doesn't exists");
- }
- else
- {
- File destValuesDir = new File(getStorageURL().getFile(), VALUE_STORAGE_DIR);
- File destDir = new File(destValuesDir, valueStorage.getId());
-
- copyDirectory(srcDir, destDir);
- }
- }
- }
-
- // copy index directory
- if (workspaceEntry.getQueryHandler() != null)
- {
- File srcDir =
- new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
- if (!PrivilegedFileHelper.exists(srcDir))
- {
- log.warn("Can't not backup index. Directory " + srcDir.getName() + " doesn't exists");
- }
- else
- {
- File destDir = new File(getStorageURL().getFile(), INDEX_DIR);
- copyDirectory(srcDir, destDir);
- }
-
- if (repository.getConfiguration().getSystemWorkspaceName().equals(workspaceName))
- {
- srcDir =
- new File(PrivilegedFileHelper.getCanonicalPath(srcDir) + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
- if (!PrivilegedFileHelper.exists(srcDir))
- {
- log.warn("Can't not backup system index. Directory " + srcDir.getName() + " doesn't exists");
- }
- else
- {
- File destDir = new File(getStorageURL().getFile(), SYSTEM_INDEX_DIR);
- copyDirectory(srcDir, destDir);
- }
- }
- }
+ backupValueStorage(workspaceEntry);
+ backupIndex(workspaceEntry);
}
catch (RepositoryConfigurationException e)
{
@@ -382,9 +303,83 @@
}
/**
+ * Backup index files.
+ *
+ * @param workspaceEntry
+ * @throws RepositoryConfigurationException
+ * @throws BackupOperationException
+ * @throws IOException
+ */
+ protected void backupIndex(WorkspaceEntry workspaceEntry) throws RepositoryConfigurationException,
+ BackupOperationException, IOException
+ {
+ if (workspaceEntry.getQueryHandler() != null)
+ {
+ File srcDir = new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new BackupOperationException("Can't backup index. Directory " + srcDir.getName() + " doesn't exists");
+ }
+ else
+ {
+ File destDir = new File(getStorageURL().getFile(), RdbmsWorkspaceInitializer.INDEX_DIR);
+ copyDirectory(srcDir, destDir);
+ }
+
+ if (repository.getConfiguration().getSystemWorkspaceName().equals(workspaceName))
+ {
+ srcDir =
+ new File(PrivilegedFileHelper.getCanonicalPath(srcDir) + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new BackupOperationException("Can't backup system index. Directory " + srcDir.getName()
+ + " doesn't exists");
+ }
+ else
+ {
+ File destDir = new File(getStorageURL().getFile(), RdbmsWorkspaceInitializer.SYSTEM_INDEX_DIR);
+ copyDirectory(srcDir, destDir);
+ }
+ }
+ }
+ }
+
+ /**
+ * Backup value storage files.
+ *
+ * @param workspaceEntry
+ * @throws RepositoryConfigurationException
+ * @throws BackupOperationException
+ * @throws IOException
+ */
+ protected void backupValueStorage(WorkspaceEntry workspaceEntry) throws RepositoryConfigurationException,
+ BackupOperationException, IOException
+ {
+ if (workspaceEntry.getContainer().getValueStorages() != null)
+ {
+ for (ValueStorageEntry valueStorage : workspaceEntry.getContainer().getValueStorages())
+ {
+ File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new BackupOperationException("Can't backup value storage. Directory " + srcDir.getName()
+ + " doesn't exists");
+ }
+ else
+ {
+ File destValuesDir = new File(getStorageURL().getFile(), RdbmsWorkspaceInitializer.VALUE_STORAGE_DIR);
+ File destDir = new File(destValuesDir, valueStorage.getId());
+
+ copyDirectory(srcDir, destDir);
+ }
+ }
+ }
+ }
+
+ /**
* Dump table.
*/
- private void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException,
+ protected void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException,
BackupOperationException
{
int getValueMethod = GET_BINARY_STREAM_METHOD;
@@ -401,10 +396,12 @@
ResultSet rs = null;
try
{
- File contentFile = new File(getStorageURL().getFile(), tableName + CONTENT_FILE_SUFFIX);
+ File contentFile =
+ new File(getStorageURL().getFile(), tableName + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX);
contentWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentFile));
- File contentLenFile = new File(getStorageURL().getFile(), tableName + CONTENT_LEN_FILE_SUFFIX);
+ File contentLenFile =
+ new File(getStorageURL().getFile(), tableName + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX);
contentLenWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentLenFile));
stmt = jdbcConn.prepareStatement(script);
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java 2010-12-06 14:25:34 UTC (rev 3602)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -34,6 +34,7 @@
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
import org.exoplatform.services.jcr.impl.dataflow.serialization.ReaderSpoolFileHolder;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
@@ -83,6 +84,8 @@
protected PersistentDataManager dataManager;
+ protected CacheableWorkspaceDataManager cacheableDataManager;
+
protected ValueFactory valueFactory;
protected StandaloneContainer container;
@@ -107,6 +110,7 @@
}
}
+ @Override
public void setUp() throws Exception
{
String containerConf = BaseStandaloneTest.class.getResource("/conf/standalone/test-configuration.xml").toString();
@@ -146,8 +150,10 @@
wsc = repository.getWorkspaceContainer("ws4");
dataManager = (PersistentDataManager)wsc.getComponent(PersistentDataManager.class);
+ cacheableDataManager = (CacheableWorkspaceDataManager)wsc.getComponent(PersistentDataManager.class);
}
+ @Override
protected void tearDown() throws Exception
{
Deleted: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java 2010-12-06 14:25:34 UTC (rev 3602)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -1,109 +0,0 @@
-/*
- * 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;
-
-import org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob;
-
-import java.io.File;
-import java.net.URL;
-import java.util.Calendar;
-
-/**
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
- * @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class TestFullBackupJob extends AbstractBackupTestCase
-{
-
- public void testRDBMSFullBackupJobSystemWorkspace() throws Exception
- {
- FullBackupJob job = new FullBackupJob();
- BackupConfig config = new BackupConfig();
- config.setRepository("db1");
- config.setWorkspace("ws");
- config.setBackupDir(new File("target/backup/testJob"));
-
- Calendar calendar = Calendar.getInstance();
-
- job.init(repositoryService.getRepository("db1"), "ws", config, calendar);
- job.run();
-
- URL url = job.getStorageURL();
- assertNotNull(url);
-
- File valuesDir = new File(url.getFile(), FullBackupJob.VALUE_STORAGE_DIR);
- assertTrue(valuesDir.exists());
- String values[] = valuesDir.list();
-
- assertEquals(values.length, 1);
- assertTrue(new File(valuesDir, values[0]).isDirectory());
-
- File indexesDir = new File(url.getFile(), FullBackupJob.INDEX_DIR);
- assertTrue(indexesDir.exists());
-
- indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
- assertTrue(indexesDir.exists());
-
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- }
-
- public void testRDBMSFullBackupJob() throws Exception
- {
- FullBackupJob job = new FullBackupJob();
- BackupConfig config = new BackupConfig();
- config.setRepository("db1");
- config.setWorkspace("ws1");
- config.setBackupDir(new File("target/backup/testJob"));
-
- Calendar calendar = Calendar.getInstance();
-
- job.init(repositoryService.getRepository("db1"), "ws1", config, calendar);
- job.run();
-
- URL url = job.getStorageURL();
- assertNotNull(url);
-
- File valuesDir = new File(url.getFile(), FullBackupJob.VALUE_STORAGE_DIR);
- assertFalse(valuesDir.exists());
-
- File indexesDir = new File(url.getFile(), FullBackupJob.INDEX_DIR);
- assertTrue(indexesDir.exists());
-
- indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
- assertFalse(indexesDir.exists());
-
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
-
- }
-}
Copied: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java (from rev 3597, jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java)
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob;
+import org.exoplatform.services.jcr.impl.core.RdbmsWorkspaceInitializer;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Calendar;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class TestRdbmsFullBackupJob extends AbstractBackupTestCase
+{
+
+ public void testRDBMSFullBackupJobSystemWorkspace() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+ assertNotNull(url);
+
+ File valuesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.VALUE_STORAGE_DIR);
+ assertTrue(valuesDir.exists());
+ String values[] = valuesDir.list();
+
+ assertEquals(values.length, 1);
+ assertTrue(new File(valuesDir, values[0]).isDirectory());
+
+ File indexesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.INDEX_DIR);
+ assertTrue(indexesDir.exists());
+
+ indexesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.SYSTEM_INDEX_DIR);
+ assertTrue(indexesDir.exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MITEM" + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MVALUE" + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MREF" + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ }
+
+ public void testRDBMSFullBackupJob() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws1");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws1", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+ assertNotNull(url);
+
+ File valuesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.VALUE_STORAGE_DIR);
+ assertFalse(valuesDir.exists());
+
+ File indexesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.INDEX_DIR);
+ assertTrue(indexesDir.exists());
+
+ indexesDir = new File(url.getFile(), RdbmsWorkspaceInitializer.SYSTEM_INDEX_DIR);
+ assertFalse(indexesDir.exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MITEM" + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MVALUE" +RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ assertTrue(new File(url.getFile(), "JCR_MREF" + RdbmsWorkspaceInitializer.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF" + RdbmsWorkspaceInitializer.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ }
+}
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -0,0 +1,156 @@
+/*
+ * 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;
+
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
+import org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob;
+import org.exoplatform.services.jcr.impl.core.RdbmsWorkspaceInitializer;
+import org.exoplatform.services.jcr.impl.core.RdbmsWorkspaceInitializerWrapper;
+import org.exoplatform.services.jcr.impl.core.SysViewWorkspaceInitializer;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class TestRdbmsWorkspaceInitializer extends AbstractBackupTestCase
+{
+ TesterConfigurationHelper helper = TesterConfigurationHelper.getInstence();
+
+ public void testRDBMSInitializerSystemWorkspace() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+
+ for (WorkspaceEntry workspaceEntry : repositoryService.getRepository("db1").getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (workspaceEntry.getName().equals("ws"))
+ {
+ String newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
+ String newIndexPath = "target/temp/index/" + IdGenerator.generate();
+
+ // set the initializer
+ WorkspaceEntry newEntry =
+ helper.getNewWs("ws", true, null, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
+ workspaceEntry.getContainer().getValueStorages());
+
+ WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
+ wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
+
+ List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
+ wieParams.add(new SimpleParameterEntry(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, new File(url
+ .getFile()).getParent()));
+
+ wiEntry.setParameters(wieParams);
+
+ newEntry.setInitializer(wiEntry);
+
+ RdbmsWorkspaceInitializerWrapper initializer =
+ new RdbmsWorkspaceInitializerWrapper(newEntry,
+ repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
+ (ValueFactoryImpl)valueFactory, null);
+
+ initializer.restoreValueFiles();
+ assertTrue(new File(newValueStoragePath).list().length > 0);
+
+ initializer.restoreIndexFiles();
+ assertTrue(new File(newIndexPath).list().length > 0);
+ assertTrue(new File(newIndexPath + "_" + SystemSearchManager.INDEX_DIR_SUFFIX).exists());
+ assertTrue(new File(newIndexPath + "_" + SystemSearchManager.INDEX_DIR_SUFFIX).list().length > 0);
+ }
+ }
+ }
+
+ public void testRDBMSInitializer() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws1");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws1", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+
+ for (WorkspaceEntry workspaceEntry : repositoryService.getRepository("db1").getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (workspaceEntry.getName().equals("ws1"))
+ {
+ String newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
+ String newIndexPath = "target/temp/index/" + IdGenerator.generate();
+
+ // set the initializer
+ WorkspaceEntry newEntry =
+ helper.getNewWs("ws1", true, null, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
+ workspaceEntry.getContainer().getValueStorages());
+
+ WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
+ wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
+
+ List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
+ wieParams.add(new SimpleParameterEntry(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, new File(url
+ .getFile()).getParent()));
+
+ wiEntry.setParameters(wieParams);
+
+ newEntry.setInitializer(wiEntry);
+
+ RdbmsWorkspaceInitializerWrapper initializer =
+ new RdbmsWorkspaceInitializerWrapper(newEntry,
+ repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
+ (ValueFactoryImpl)valueFactory, null);
+
+ initializer.restoreValueFiles();
+ assertFalse(new File(newValueStoragePath).exists());
+
+ initializer.restoreIndexFiles();
+ assertTrue(new File(newIndexPath).list().length > 0);
+ assertFalse(new File(newIndexPath + "_" + SystemSearchManager.INDEX_DIR_SUFFIX).exists());
+ }
+ }
+ }
+
+}
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializerWrapper.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -0,0 +1,65 @@
+/*
+ * 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.impl.core;
+
+import org.exoplatform.services.jcr.access.AccessManager;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
+
+import java.io.IOException;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 04.12.2006
+ *
+ * For testing purpose
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id: SessionDataManagerTestWrapper.java 11907 2008-03-13 15:36:21Z ksm $
+ */
+public class RdbmsWorkspaceInitializerWrapper extends RdbmsWorkspaceInitializer
+{
+
+ public RdbmsWorkspaceInitializerWrapper(WorkspaceEntry config, RepositoryEntry repConfig,
+ CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
+ LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
+ AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ {
+ super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
+ accessManager);
+ }
+
+ public void restoreValueFiles() throws RepositoryConfigurationException, IOException
+ {
+ super.restoreValueStorage();
+ }
+
+ public void restoreIndexFiles() throws RepositoryConfigurationException, IOException
+ {
+ super.restoreIndex();
+ }
+}
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/util/TesterConfigurationHelper.java 2010-12-06 14:34:57 UTC (rev 3603)
@@ -0,0 +1,347 @@
+/*
+ * 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.util;
+
+import org.apache.commons.dbcp.BasicDataSourceFactory;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.CacheEntry;
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
+import org.exoplatform.services.jcr.config.LockPersisterEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jcr.RepositoryException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk@gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id: ConfigurationHelper.java 11907 2008-03-13 15:36:21Z ksm $
+ */
+public class TesterConfigurationHelper
+{
+ private static Log log = ExoLogger.getLogger("exo.jcr.component.core.ConfigurationHelper");
+
+ private static TesterConfigurationHelper instence;
+
+ private TesterConfigurationHelper()
+ {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.exoplatform.services.naming.SimpleContextFactory");
+ }
+
+ public void createWorkspace(WorkspaceEntry workspaceEntry, ExoContainer container)
+ throws RepositoryConfigurationException, RepositoryException
+ {
+ RepositoryService service = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+ RepositoryImpl defRep;
+
+ defRep = (RepositoryImpl)service.getDefaultRepository();
+ defRep.configWorkspace(workspaceEntry);
+ defRep.createWorkspace(workspaceEntry.getName());
+
+ }
+
+ public String getNewDataSource(String type) throws Exception
+ {
+
+ String newDS = IdGenerator.generate();
+ Properties properties = new Properties();
+
+ properties.setProperty("driverClassName", "org.hsqldb.jdbcDriver");
+ String newurl = "jdbc:hsqldb:file:target/temp/data/" + newDS;
+
+ log.info("New url " + newurl);
+
+ properties.setProperty("url", newurl);
+ properties.setProperty("username", "sa");
+ properties.setProperty("password", "");
+ DataSource bds = BasicDataSourceFactory.createDataSource(properties);
+ if (!newurl.contains("hsqldb"))
+ {
+ createDatabase(bds, newDS);
+ }
+
+ new InitialContext().bind(newDS, bds);
+ return newDS;
+
+ }
+
+ public WorkspaceEntry getNewWs(String wsName, boolean isMultiDb, String dsName, String vsPath, String indexDir,
+ ContainerEntry entry, List<ValueStorageEntry> valueStorage) throws Exception
+ {
+
+ String dbDialect = null;
+ if (dsName != null)
+ {
+ DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds != null)
+ {
+ Connection jdbcConn = null;
+
+ jdbcConn = ds.getConnection();
+ dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
+
+ }
+ }
+
+ if (dsName == null)
+ {
+ dsName = getNewDataSource("");
+ }
+
+ List params = new ArrayList();
+
+ params.add(new SimpleParameterEntry("source-name", dsName));
+ params.add(new SimpleParameterEntry("db-type", "generic"));
+ params.add(new SimpleParameterEntry("multi-db", isMultiDb ? "true" : "false"));
+ params.add(new SimpleParameterEntry("update-storage", "true"));
+ params.add(new SimpleParameterEntry("max-buffer-size", "204800"));
+
+ if (dbDialect != null)
+ {
+ params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, dbDialect));
+ }
+ else if (entry.getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT) != null)
+ {
+ params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, entry
+ .getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT)));
+ }
+
+ String oldSwap = entry.getParameterValue("swap-directory");
+ String newSwap = oldSwap.substring(0, oldSwap.lastIndexOf('/')) + '/' + wsName;
+
+ params.add(new SimpleParameterEntry("swap-directory", newSwap));
+
+ ContainerEntry containerEntry =
+ new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
+ (ArrayList)params);
+ containerEntry.setParameters(params);
+
+ // value storage
+ ArrayList list = new ArrayList();
+ if (valueStorage != null)
+ {
+ for (ValueStorageEntry oldValueStorageEntry : valueStorage)
+ {
+ ArrayList<ValueStorageFilterEntry> vsparams = new ArrayList<ValueStorageFilterEntry>();
+ ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
+ filterEntry.setPropertyType("Binary");
+ vsparams.add(filterEntry);
+
+ ValueStorageEntry valueStorageEntry =
+ new ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.SimpleFileValueStorage",
+ vsparams);
+ ArrayList<SimpleParameterEntry> spe = new ArrayList<SimpleParameterEntry>();
+ spe.add(new SimpleParameterEntry("path", vsPath));
+ valueStorageEntry.setId(oldValueStorageEntry.getId());
+ valueStorageEntry.setParameters(spe);
+ valueStorageEntry.setFilters(vsparams);
+
+ // containerEntry.setValueStorages();
+ containerEntry.setParameters(params);
+
+ list.add(valueStorageEntry);
+ }
+ }
+
+ containerEntry.setValueStorages(list);
+
+ // Indexer
+ ArrayList qParams = new ArrayList();
+ qParams.add(new SimpleParameterEntry("index-dir", indexDir));
+ QueryHandlerEntry qEntry =
+ new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+
+ WorkspaceEntry workspaceEntry =
+ new WorkspaceEntry(wsName != null ? wsName : IdGenerator.generate(), "nt:unstructured");
+ workspaceEntry.setContainer(containerEntry);
+
+ ArrayList cacheParams = new ArrayList();
+
+ cacheParams.add(new SimpleParameterEntry("maxSize", "2000"));
+ cacheParams.add(new SimpleParameterEntry("liveTime", "20m"));
+ CacheEntry cacheEntry = new CacheEntry(cacheParams);
+ cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
+
+ workspaceEntry.setCache(cacheEntry);
+
+ workspaceEntry.setQueryHandler(qEntry);
+
+ LockManagerEntry lockManagerEntry = new LockManagerEntry();
+ lockManagerEntry.setTimeout(900000);
+ LockPersisterEntry persisterEntry = new LockPersisterEntry();
+ persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
+ ArrayList lpParams = new ArrayList();
+ lpParams.add(new SimpleParameterEntry("path", "../temp/lock"));
+ persisterEntry.setParameters(lpParams);
+ lockManagerEntry.setPersister(persisterEntry);
+ workspaceEntry.setLockManager(lockManagerEntry);
+
+ // workspaceEntry
+ return workspaceEntry;
+ }
+
+ // public WorkspaceEntry getNewWsOnDataSource(String wsName, boolean isMultiDb, String dsName, String vsPath,
+ // ContainerEntry entry) throws Exception
+ // {
+ //
+ // String dbDialect = null;
+ // if (dsName != null)
+ // {
+ // DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ // if (ds != null)
+ // {
+ // Connection jdbcConn = null;
+ //
+ // jdbcConn = ds.getConnection();
+ // dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
+ // }
+ // }
+ //
+ // List params = new ArrayList();
+ //
+ // if (isMultiDb && dsName == null)
+ // {
+ // dsName = getNewDataSource("");
+ // }
+ //
+ // params.add(new SimpleParameterEntry("sourceName", dsName));
+ // params.add(new SimpleParameterEntry("db-type", "generic"));
+ // params.add(new SimpleParameterEntry("multi-db", isMultiDb ? "true" : "false"));
+ // params.add(new SimpleParameterEntry("update-storage", "true"));
+ // params.add(new SimpleParameterEntry("max-buffer-size", "204800"));
+ //
+ // if (dbDialect != null)
+ // {
+ // params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, dbDialect));
+ // }
+ // else if (entry.getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT) != null)
+ // {
+ // params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, entry
+ // .getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT)));
+ // }
+ //
+ // String oldSwap = entry.getParameterValue("swap-directory");
+ // String newSwap = oldSwap.substring(0, oldSwap.lastIndexOf('/')) + '/' + wsName;
+ //
+ // params.add(new SimpleParameterEntry("swap-directory", newSwap));
+ //
+ // ContainerEntry containerEntry =
+ // new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
+ // (ArrayList)params);
+ // containerEntry.setParameters(params);
+ //
+ // if (vsPath != null)
+ // {
+ //
+ // ArrayList<ValueStorageFilterEntry> vsparams = new ArrayList<ValueStorageFilterEntry>();
+ // ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
+ // filterEntry.setPropertyType("Binary");
+ // vsparams.add(filterEntry);
+ //
+ // ValueStorageEntry valueStorageEntry =
+ // new ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.SimpleFileValueStorage", vsparams);
+ // ArrayList<SimpleParameterEntry> spe = new ArrayList<SimpleParameterEntry>();
+ // spe.add(new SimpleParameterEntry("path", vsPath));
+ // valueStorageEntry.setId(IdGenerator.generate());
+ // valueStorageEntry.setParameters(spe);
+ // valueStorageEntry.setFilters(vsparams);
+ //
+ // // containerEntry.setValueStorages();
+ // containerEntry.setParameters(params);
+ // ArrayList list = new ArrayList(1);
+ // list.add(valueStorageEntry);
+ //
+ // containerEntry.setValueStorages(list);
+ //
+ // }
+ //
+ // // Indexer
+ // ArrayList qParams = new ArrayList();
+ // qParams.add(new SimpleParameterEntry("indexDir", "../temp/index/" + IdGenerator.generate()));
+ // QueryHandlerEntry qEntry =
+ // new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+ //
+ // WorkspaceEntry workspaceEntry =
+ // new WorkspaceEntry(wsName != null ? wsName : IdGenerator.generate(), "nt:unstructured");
+ // workspaceEntry.setContainer(containerEntry);
+ //
+ // ArrayList cacheParams = new ArrayList();
+ //
+ // cacheParams.add(new SimpleParameterEntry("maxSize", "2000"));
+ // cacheParams.add(new SimpleParameterEntry("liveTime", "20m"));
+ // CacheEntry cacheEntry = new CacheEntry(cacheParams);
+ // cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
+ //
+ // workspaceEntry.setCache(cacheEntry);
+ //
+ // workspaceEntry.setQueryHandler(qEntry);
+ //
+ // LockManagerEntry lockManagerEntry = new LockManagerEntry();
+ // lockManagerEntry.setTimeout(900000);
+ // LockPersisterEntry persisterEntry = new LockPersisterEntry();
+ // persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
+ // ArrayList lpParams = new ArrayList();
+ // lpParams.add(new SimpleParameterEntry("path", "../temp/lock"));
+ // persisterEntry.setParameters(lpParams);
+ // lockManagerEntry.setPersister(persisterEntry);
+ // workspaceEntry.setLockManager(lockManagerEntry);
+ //
+ // // workspaceEntry
+ // return workspaceEntry;
+ // }
+
+ private void createDatabase(DataSource ds, String dbName) throws SQLException
+ {
+ Connection connection = ds.getConnection();
+ PreparedStatement st = connection.prepareStatement("create database " + dbName);
+ st.executeQuery();
+ }
+
+ public static TesterConfigurationHelper getInstence()
+ {
+ if (instence == null)
+ {
+ instence = new TesterConfigurationHelper();
+ }
+
+ return instence;
+ }
+}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-06 14:25:34 UTC (rev 3602)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-06 14:34:57 UTC (rev 3603)
@@ -39,7 +39,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="target/temp/values/backup" />
+ <property name="path" value="target/temp/values/db1_ws" />
</properties>
<filters>
<filter property-type="Binary" />
15 years, 5 months
exo-jcr SVN: r3602 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-06 09:25:34 -0500 (Mon, 06 Dec 2010)
New Revision: 3602
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
Log:
EXOJCR-1078: implementation RDBMS workspace initialzer
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-06 09:33:20 UTC (rev 3601)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-12-06 14:25:34 UTC (rev 3602)
@@ -73,7 +73,7 @@
*/
public class BackupWorkspaceInitializer extends SysViewWorkspaceInitializer
{
- private final String restoreDir;
+ protected final String restoreDir;
private FileCleaner fileCleaner;
@@ -97,9 +97,13 @@
String fullBackupPath = getFullBackupPath();
if (fullBackupPath == null)
- throw new RepositoryException("Can't find full backup file");
+ {
+ throw new RepositoryException("Can't find full backup storage");
+ }
else
+ {
restorePath = fullBackupPath;
+ }
this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
@@ -153,12 +157,14 @@
}
}
- private void incrementalRead() throws RepositoryException
+ protected void incrementalRead() throws RepositoryException
{
try
{
for (File incrBackupFile : getIncrementalFiles())
+ {
incrementalRestore(incrBackupFile);
+ }
}
catch (FileNotFoundException e)
{
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RdbmsWorkspaceInitializer.java 2010-12-06 14:25:34 UTC (rev 3602)
@@ -0,0 +1,597 @@
+/*
+ * 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.impl.core;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.services.jcr.access.AccessManager;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: RdbmsWorkspaceInitializer.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RdbmsWorkspaceInitializer extends BackupWorkspaceInitializer
+{
+ /**
+ * Logger.
+ */
+ protected static final Log log = ExoLogger.getLogger("exo.jcr.component.core.RdbmsWorkspaceInitializer");
+
+ /**
+ * Index directory in full backup storage.
+ */
+ public static final String INDEX_DIR = "index";
+
+ /**
+ * System index directory in full backup storage.
+ */
+ public static final String SYSTEM_INDEX_DIR = INDEX_DIR + "_" + SystemSearchManager.INDEX_DIR_SUFFIX;
+
+ /**
+ * Value storage directory in full backup storage.
+ */
+ public static final String VALUE_STORAGE_DIR = "values";
+
+ /**
+ * Suffix for content file.
+ */
+ public static final String CONTENT_FILE_SUFFIX = ".dump";
+
+ /**
+ * Suffix for content length file.
+ */
+ public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
+
+ /**
+ * Constructor RdbmsWorkspaceInitializer.
+ */
+ public RdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
+ CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
+ LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
+ AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ {
+ super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
+ accessManager);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NodeData initWorkspace() throws RepositoryException
+ {
+ if (isWorkspaceInitialized())
+ {
+ return (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
+ }
+
+ Connection jdbcConn = null;
+ Integer transactionIsolation = null;
+ try
+ {
+ long start = System.currentTimeMillis();
+
+ String dsName = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ if (dsName == null)
+ {
+ throw new RepositoryConfigurationException("Data source name not found in workspace configuration "
+ + workspaceName);
+ }
+
+ String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+ if (multiDb == null)
+ {
+ throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
+ + " parameter not found in workspace " + workspaceName + " configuration");
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ String dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
+
+ transactionIsolation = jdbcConn.getTransactionIsolation();
+ jdbcConn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+
+ // resolve constraint name depends on database
+ String constraintName;
+ if (dbDialect.equals(DBConstants.DB_DIALECT_DB2) || dbDialect.equals(DBConstants.DB_DIALECT_DB2V8))
+ {
+ constraintName = "JCR_FK_" + (Boolean.parseBoolean(multiDb) ? "M" : "S") + "ITEM_PAREN";
+ }
+ else
+ {
+ constraintName = "JCR_FK_" + (Boolean.parseBoolean(multiDb) ? "M" : "S") + "ITEM_PARENT";
+ }
+
+ // restore from full backup
+ // TODO
+
+ restoreValueStorage();
+ restoreIndex();
+
+ // restore from incremental backup
+ incrementalRead();
+
+ final NodeData root = (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
+
+ log.info("Workspace [" + workspaceName + "] restored from storage " + restorePath + " in "
+ + (System.currentTimeMillis() - start) * 1d / 1000 + "sec");
+
+ return root;
+
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (NamingException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ if (transactionIsolation != null)
+ {
+ jdbcConn.setTransactionIsolation(transactionIsolation);
+ }
+
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Restore index from backup.
+ */
+ protected void restoreIndex() throws RepositoryConfigurationException, IOException
+ {
+ File indexDir = new File(restorePath, INDEX_DIR);
+ File systemIndexDir = new File(restorePath, SYSTEM_INDEX_DIR);
+
+ if (workspaceEntry.getQueryHandler() != null)
+ {
+ if (!PrivilegedFileHelper.exists(indexDir))
+ {
+ throw new RepositoryConfigurationException("Can't restore index. Directory " + indexDir.getName()
+ + " doesn't exists");
+ }
+ else
+ {
+ File destDir =
+ new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
+ copyDirectory(indexDir, destDir);
+ }
+
+ // try to restore system index
+ if (repositoryEntry.getSystemWorkspaceName().equals(workspaceName))
+ {
+ if (!PrivilegedFileHelper.exists(systemIndexDir))
+ {
+ throw new RepositoryConfigurationException("Can't restore system index. Directory "
+ + systemIndexDir.getName() + " doesn't exists");
+ }
+ else
+ {
+ File destDir =
+ new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR) + "_"
+ + SystemSearchManager.INDEX_DIR_SUFFIX);
+ copyDirectory(systemIndexDir, destDir);
+ }
+ }
+ else if (PrivilegedFileHelper.exists(systemIndexDir))
+ {
+ throw new RepositoryConfigurationException("Workspace [" + workspaceName
+ + "] is not a system in repository configuration but system index backup files exist");
+ }
+ }
+ else
+ {
+ if (PrivilegedFileHelper.exists(indexDir) || PrivilegedFileHelper.exists(systemIndexDir))
+ {
+ throw new RepositoryConfigurationException("Query handler didn't configure in workspace [" + workspaceName
+ + "] configuration but index backup files exist");
+ }
+ }
+ }
+
+ /**
+ * Restoring value storage from backup.
+ */
+ protected void restoreValueStorage() throws RepositoryConfigurationException, IOException
+ {
+ File backupValueStorageDir = new File(restorePath, VALUE_STORAGE_DIR);
+ if (workspaceEntry.getContainer().getValueStorages() != null)
+ {
+ List<ValueStorageEntry> valueStorages = workspaceEntry.getContainer().getValueStorages();
+ String[] valueStoragesFiles = PrivilegedFileHelper.list(backupValueStorageDir);
+
+ if ((valueStoragesFiles == null && valueStorages.size() != 0)
+ || (valueStoragesFiles != null && valueStoragesFiles.length != valueStorages.size()))
+ {
+ throw new RepositoryConfigurationException("Workspace configuration [" + workspaceName
+ + "] has a different amount of value storages than exist in backup");
+ }
+
+ for (ValueStorageEntry valueStorage : valueStorages)
+ {
+ File srcDir = new File(backupValueStorageDir, valueStorage.getId());
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new RepositoryConfigurationException("Can't restore value storage. Directory " + srcDir.getName()
+ + " doesn't exists");
+ }
+ else
+ {
+ File destDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+
+ copyDirectory(srcDir, destDir);
+ }
+ }
+ }
+ else
+ {
+ if (PrivilegedFileHelper.exists(backupValueStorageDir))
+ {
+ throw new RepositoryConfigurationException("Value storage didn't configure in workspace [" + workspaceName
+ + "] configuration but value storage backup files exist");
+ }
+ }
+ }
+
+ public static void restore(Properties props)
+ {
+// File targetDir = new File(props.getProperty("targetdir"));
+ //
+ // File sitem = new File(targetDir, "jcr_sitem.dump");
+ // sitem.exists();
+ //
+ // Statement st = dbConn.createStatement();
+ // st.execute("ALTER TABLE JCR_SITEM DROP CONSTRAINT JCR_FK_SITEM_PARENT");
+ // dbConn.commit();
+ //
+ // restoreTable(dbConn, sitem);
+ //
+ // st = dbConn.createStatement();
+ // st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
+ // dbConn.commit();
+ //
+ // for (File dumpFile : targetDir.listFiles())
+ // {
+ // if (dumpFile.getName().contains(".dump") && !dumpFile.getName().contains("jcr_sitem"))
+ // {
+ // restoreTable(dbConn, dumpFile);
+ // }
+ // }
+ //
+ // dbConn.close();
+ //
+ // copyDirectory(new File(targetDir, "values"), new File(props.getProperty("valuestoragedir")));
+ // copyDirectory(new File(targetDir, "index"), new File(props.getProperty("indexdir")));
+ // return;
+
+ }
+
+ /**
+ * Copy directory.
+ *
+ * @param srcPath
+ * source path
+ * @param dstPath
+ * destination path
+ * @throws IOException
+ * if any exception occurred
+ */
+ private void copyDirectory(File srcPath, File dstPath) throws IOException
+ {
+ if (PrivilegedFileHelper.isDirectory(srcPath))
+ {
+ if (!PrivilegedFileHelper.exists(dstPath))
+ {
+ PrivilegedFileHelper.mkdirs(dstPath);
+ }
+
+ String files[] = PrivilegedFileHelper.list(srcPath);
+ for (int i = 0; i < files.length; i++)
+ {
+ copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
+ }
+ }
+ else
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ in = PrivilegedFileHelper.fileInputStream(srcPath);
+ out = PrivilegedFileHelper.fileOutputStream(dstPath);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[2048];
+
+ int len;
+
+ while ((len = in.read(buf)) > 0)
+ {
+ out.write(buf, 0, len);
+ }
+ }
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ }
+ }
+
+ private static void restoreTable(Connection dbConn, File dumpFile)
+ {
+ String INSERT_NODE = null;
+
+ ObjectReader dump = null;
+ ObjectReader leng = null;
+ try
+ {
+ dbConn.setAutoCommit(false);
+
+ dump = new ObjectReaderImpl(new FileInputStream(dumpFile));
+ String tableName = dump.readString();
+ int columnCount = dump.readInt();
+
+ int[] columnType = new int[columnCount];
+ for (int i = 0; i < columnCount; i++)
+ {
+ columnType[i] = dump.readInt();
+ }
+
+ leng = new ObjectReaderImpl(new FileInputStream(new File(dumpFile.getParentFile(), tableName + ".leng")));
+
+ for (int i = 0; i < columnCount; i++)
+ {
+ if (i == 0)
+ {
+ INSERT_NODE = "INSERT INTO " + tableName + " VALUES(?";
+ }
+ else
+ {
+ INSERT_NODE += ",?";
+ }
+ if (i == columnCount - 1)
+ {
+ INSERT_NODE += ")";
+ }
+ }
+
+ PreparedStatement insertNode = dbConn.prepareStatement(INSERT_NODE);
+ while (true)
+ {
+ try
+ {
+ for (int i = 0; i < columnCount; i++)
+ {
+ long len = leng.readLong();
+ if (len >= 0)
+ {
+ InputStream stream = spoolInputStream(dump, len);
+ if (columnType[i] == Types.INTEGER || columnType[i] == Types.BIGINT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String p = new String(readBuffer);
+ int l = Integer.parseInt(p);
+
+ insertNode.setLong(i + 1, l);
+ }
+ else if (columnType[i] == Types.BOOLEAN || columnType[i] == Types.BIT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String p = new String(readBuffer);
+ insertNode.setBoolean(i + 1, p.equals("t"));
+ }
+ else
+ {
+ // for Postgres
+ insertNode.setBinaryStream(i + 1, stream, (int)len);
+ }
+ }
+ else
+ {
+ insertNode.setNull(i + 1, columnType[i]);
+ }
+ }
+ // insertNode.executeUpdate();
+ insertNode.addBatch();
+ }
+ catch (EOFException e)
+ {
+ break;
+ }
+ }
+ insertNode.executeBatch();
+
+ insertNode.close();
+
+ dump.close();
+ leng.close();
+
+ dbConn.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ try
+ {
+ dbConn.rollback();
+ }
+ catch (SQLException e1)
+ {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ static public InputStream spoolInputStream(ObjectReader in, long maxLen) throws IOException
+ {
+ byte[] buffer = new byte[0];
+ byte[] tmpBuff;
+ long len = 0;
+ File spoolFile = null;
+ OutputStream sfout = null;
+
+ try
+ {
+ while (true)
+ {
+ int needToRead = maxLen - len > 2048 ? 2048 : (int)(maxLen - len);
+ tmpBuff = new byte[needToRead];
+
+ if (needToRead <= 0)
+ {
+ break;
+ }
+
+ in.readFully(tmpBuff);
+
+ if (sfout != null)
+ {
+ sfout.write(tmpBuff);
+ }
+ else if (len + needToRead > 200 * 1024)
+ {
+ spoolFile = File.createTempFile("swapFile", ".tmp");
+ sfout = new FileOutputStream(spoolFile);
+
+ sfout.write(buffer);
+ sfout.write(tmpBuff);
+ buffer = null;
+ }
+ else
+ {
+ // reallocate new buffer and spool old buffer contents
+ byte[] newBuffer = new byte[(int)(len + needToRead)];
+ System.arraycopy(buffer, 0, newBuffer, 0, (int)len);
+ System.arraycopy(tmpBuff, 0, newBuffer, (int)len, needToRead);
+ buffer = newBuffer;
+ }
+
+ len += needToRead;
+ }
+
+ if (buffer != null)
+ {
+ return new ByteArrayInputStream(buffer);
+ }
+ else
+ {
+ return new FileInputStream(spoolFile);
+ }
+ }
+ finally
+ {
+ if (sfout != null)
+ sfout.close();
+ }
+ }
+
+}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-06 09:33:20 UTC (rev 3601)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-12-06 14:25:34 UTC (rev 3602)
@@ -89,6 +89,16 @@
protected final String workspaceName;
+ /**
+ * Workspace entry.
+ */
+ protected final WorkspaceEntry workspaceEntry;
+
+ /**
+ * Repository Entry.
+ */
+ protected final RepositoryEntry repositoryEntry;
+
protected final DataManager dataManager;
private final NamespaceRegistryImpl namespaceRegistry;
@@ -397,27 +407,8 @@
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
{
-
- this.workspaceName = config.getName();
-
- this.dataManager = dataManager;
-
- this.namespaceRegistry = namespaceRegistry;
- this.locationFactory = locationFactory;
-
- this.fileCleaner = valueFactory.getFileCleaner();
- this.maxBufferSize =
- config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
- WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
-
- this.restorePath =
- config.getInitializer().getParameterValue(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, null);
- if (this.restorePath == null)
- throw new RepositoryConfigurationException("Workspace (" + workspaceName
- + ") RestoreIntializer should have mandatory parameter "
- + SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER);
-
- this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+ this(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
+ accessManager, config.getInitializer().getParameterValue(RESTORE_PATH_PARAMETER, null));
}
/**
@@ -449,8 +440,10 @@
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
AccessManager accessManager, String restorePath) throws RepositoryException
{
-
+ this.workspaceEntry = config;
this.workspaceName = config.getName();
+
+ this.repositoryEntry = repConfig;
this.dataManager = dataManager;
@@ -464,6 +457,12 @@
this.restorePath = restorePath;
this.tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+ if (this.restorePath == null)
+ {
+ throw new RepositoryException(RESTORE_PATH_PARAMETER + " is absent in workpsace [" + workspaceName
+ + "] configuration ");
+ }
}
/**
15 years, 5 months
exo-jcr SVN: r3601 - kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-06 04:33:20 -0500 (Mon, 06 Dec 2010)
New Revision: 3601
Modified:
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-1073 : The problem with TestRPCServiceImpl was fixed.
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-06 07:57:47 UTC (rev 3600)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-06 09:33:20 UTC (rev 3601)
@@ -833,7 +833,7 @@
};
t.start();
service1.stop();
- Thread.sleep(5000);
+ listener2.waitTopologyChange();
assertFalse(listener1.coordinatorHasChanged);
assertTrue(listener1.isCoordinator);
assertEquals(2, listener1.count);
@@ -1188,6 +1188,8 @@
private boolean coordinatorHasChanged;
private boolean isCoordinator;
private int count;
+
+ private CountDownLatch lock;
/**
* @see org.exoplatform.services.rpc.TopologyChangeListener#onChange(org.exoplatform.services.rpc.TopologyChangeEvent)
@@ -1197,6 +1199,17 @@
this.coordinatorHasChanged = event.isCoordinatorHasChanged();
this.isCoordinator = event.isCoordinator();
count++;
+
+ if (lock != null)
+ {
+ lock.countDown();
+ }
}
+
+ public void waitTopologyChange() throws InterruptedException
+ {
+ lock = new CountDownLatch(1);
+ lock.await();
+ }
}
}
15 years, 5 months
exo-jcr SVN: r3600 - in kernel/trunk/exo.kernel.component.common: src/test/java/org/exoplatform/services/rpc/impl and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-12-06 02:57:47 -0500 (Mon, 06 Dec 2010)
New Revision: 3600
Modified:
kernel/trunk/exo.kernel.component.common/pom.xml
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-1073 : The problem with TestRPCServiceImpl was fixed.
Modified: kernel/trunk/exo.kernel.component.common/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.common/pom.xml 2010-12-03 13:33:47 UTC (rev 3599)
+++ kernel/trunk/exo.kernel.component.common/pom.xml 2010-12-06 07:57:47 UTC (rev 3600)
@@ -128,7 +128,6 @@
</systemProperties>
<excludes>
<exclude>**/TransactionTest.java</exclude>
- <exclude>**/TestRPCServiceImpl.java</exclude>
</excludes>
</configuration>
</plugin>
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-03 13:33:47 UTC (rev 3599)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-12-06 07:57:47 UTC (rev 3600)
@@ -18,6 +18,13 @@
*/
package org.exoplatform.services.rpc.impl;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
@@ -31,13 +38,6 @@
import org.exoplatform.test.BasicTestCase;
import org.jgroups.Address;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
/**
* This is the unit test class for the service {@link RPCServiceImpl}
*
@@ -833,6 +833,7 @@
};
t.start();
service1.stop();
+ Thread.sleep(5000);
assertFalse(listener1.coordinatorHasChanged);
assertTrue(listener1.isCoordinator);
assertEquals(2, listener1.count);
15 years, 5 months