exo-jcr SVN: r3680 - in jcr/trunk: exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-20 04:24:58 -0500 (Mon, 20 Dec 2010)
New Revision: 3680
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
Log:
EXOJCR-747: restore single workspace into existed one in case of multi-db is not supported
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-12-20 09:24:04 UTC (rev 3679)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-12-20 09:24:58 UTC (rev 3680)
@@ -25,6 +25,7 @@
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -100,6 +101,29 @@
+ " did not found in current repository " + repositoryName + " configuration");
}
+ boolean isMultiDb;
+ try
+ {
+ String multiDb = wEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+ if (multiDb == null)
+ {
+ throw new RepositoryConfigurationException("Parameter " + JDBCWorkspaceDataContainer.MULTIDB
+ + " not found in workspace configuration " + wEntry.getName());
+ }
+
+ isMultiDb = Boolean.parseBoolean(multiDb);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new WorkspaceRestoreException("Can't define " + JDBCWorkspaceDataContainer.MULTIDB + " parameter", e);
+ }
+
+ if (isMultiDb)
+ {
+ throw new WorkspaceRestoreException(
+ "Restore of single workspace into existed one for multi-db is not supported");
+ }
+
boolean isSystem =
repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName()
.equals(wEntry.getName());
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-12-20 09:24:04 UTC (rev 3679)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-12-20 09:24:58 UTC (rev 3680)
@@ -36,10 +36,13 @@
import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import java.io.File;
import java.io.FileFilter;
+import java.sql.Connection;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -54,6 +57,8 @@
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
/**
* Created by The eXo Platform SAS Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
@@ -295,7 +300,8 @@
newWorkspaceName = workspaceMapping.get(wsEntry.getName());
}
- WorkspaceEntry newWSEntry = makeWorkspaceEntry(wsEntry, newWorkspaceName, repoName, sourceName);
+ WorkspaceEntry newWSEntry =
+ makeWorkspaceEntry(wsEntry, newWorkspaceName, repoName, sourceName);
wsEntries.add(newWSEntry);
}
@@ -468,7 +474,7 @@
// get current workspace configuration
WorkspaceEntry wEntry = null;;
for (WorkspaceEntry entry : repositoryService.getRepository(repositoryName).getConfiguration()
- .getWorkspaceEntries())
+ .getWorkspaceEntries())
{
if (entry.getName().equals(workspaceName))
{
@@ -480,12 +486,12 @@
if (wEntry == null)
{
throw new WorkspaceRestoreException("Workspace " + workspaceName + " did not found in current repository "
- + repositoryName + " configuration");
+ + repositoryName + " configuration");
}
boolean isSystem =
- repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName().equals(
- wEntry.getName());
+ repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName()
+ .equals(wEntry.getName());
//close all session
forceCloseSession(repositoryName, wEntry.getName());
@@ -493,6 +499,70 @@
repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
//clean database
+ // dbCleanerService.cleanWorkspaceData(wEntry);
+ DataSource ds =
+ (DataSource)new InitialContext().lookup(wEntry.getContainer().getParameterValue(
+ JDBCWorkspaceDataContainer.SOURCE_NAME));
+ Connection conn = ds.getConnection();
+
+ if (conn.getMetaData().getTables(null, null, "JCR_MITEM", new String[]{"TABLE"}).next())
+ {
+ Statement st = conn.createStatement();
+ st.execute("DROP TABLE JCR_MVALUE");
+ st.execute("DROP TABLE JCR_MREF");
+ st.execute("DROP TABLE JCR_MITEM");
+ conn.commit();
+ st.close();
+ conn.close();
+ }
+ else if (conn.getMetaData().getTables(null, null, "JCR_SITEM", new String[]{"TABLE"}).next())
+ {
+ Statement st = conn.createStatement();
+ st.execute("DROP TABLE JCR_SVALUE");
+ st.execute("DROP TABLE JCR_SREF");
+ st.execute("DROP TABLE JCR_SITEM");
+ conn.commit();
+ st.close();
+ conn.close();
+ }
+
+ //clean index
+ indexCleanHelper.removeWorkspaceIndex(wEntry, isSystem);
+
+ //clean value storage
+ valueStorageCleanHelper.removeWorkspaceValueStorage(wEntry);
+ }
+
+ protected void removeWorkspaceFullySingleDB(String repositoryName, String workspaceName) throws Exception
+ {
+ // get current workspace configuration
+ WorkspaceEntry wEntry = null;;
+ for (WorkspaceEntry entry : repositoryService.getRepository(repositoryName).getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (entry.getName().equals(workspaceName))
+ {
+ wEntry = entry;
+ break;
+ }
+ }
+
+ if (wEntry == null)
+ {
+ throw new WorkspaceRestoreException("Workspace " + workspaceName + " did not found in current repository "
+ + repositoryName + " configuration");
+ }
+
+ boolean isSystem =
+ repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName()
+ .equals(wEntry.getName());
+
+ //close all session
+ forceCloseSession(repositoryName, wEntry.getName());
+
+ repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
+
+ //clean database
dbCleanerService.cleanWorkspaceData(wEntry);
//clean index
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-20 09:24:04 UTC (rev 3679)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2010-12-20 09:24:58 UTC (rev 3680)
@@ -28,11 +28,11 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.InputStream;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Value;
import javax.jcr.lock.Lock;
/**
@@ -250,7 +250,7 @@
ws1TestRoot.addNode("node_102").setProperty("exo:data", new FileInputStream(tempf));
ws1TestRoot.save(); // log here via listener
- ws1TestRoot.getNode("node_2").setProperty("exo:data", (InputStream)null); // remove property
+ ws1TestRoot.getNode("node_2").setProperty("exo:data", (Value)null); // remove property
ws1TestRoot.getNode("node_3").setProperty("exo:data", new ByteArrayInputStream("aaa".getBytes())); // set
// aaa
// bytes
@@ -905,7 +905,7 @@
}
public void testRepositoryFullBackupAsynchronusRestore() throws Exception
- {
+ {
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -982,7 +982,7 @@
}
else
fail("There are no backup files in " + backDir.getAbsolutePath());
- }
+ }
public void testRepositoryFullBackupAsynchronusRestoreWorkspaceMapping() throws Exception
{
@@ -1009,7 +1009,7 @@
// stop fullBackup
- backup.stopBackup(bch);
+ backup.stopBackup(bch);
// restore
RepositoryEntry newRepositoryEntry =
@@ -1085,7 +1085,7 @@
}
public void testAutoStopRepositoryBackupIncrRepetion() throws Exception
- {
+ {
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1100,20 +1100,20 @@
final RepositoryBackupChain bch = backup.startBackup(config);
while (!bch.isFinished())
- {
+ {
Thread.yield();
Thread.sleep(50);
- }
+ }
Thread.sleep(5000);
for (RepositoryBackupChain chain : backup.getCurrentRepositoryBackups())
if (bch.getBackupId().equals(chain.getBackupId()))
fail("The backup with id '" + chain.getBackupId() + "' should not be active");
- }
+ }
public void testRepositoryRestoreFail() throws Exception
- {
+ {
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1144,8 +1144,7 @@
// restore
RepositoryEntry newRepositoryEntry =
- makeRepositoryEntry(repoName, getReposityToBackup().getConfiguration(),
- dataSourceToRepositoryRestore, null);
+ makeRepositoryEntry(repoName, getReposityToBackup().getConfiguration(), dataSourceToRepositoryRestore, null);
//create broken system workspaceEntry
newRepositoryEntry.getWorkspaceEntries().get(0).getQueryHandler().setType("gg");
@@ -1165,8 +1164,8 @@
}
// check
- try
- {
+ try
+ {
ManageableRepository restoredRepository = repositoryService.getRepository(repoName);
fail("The repository " + repositoryNameToRestore + "shoulde not exists.");
}
@@ -1203,7 +1202,7 @@
{
Thread.yield();
Thread.sleep(50);
- }
+ }
// add data
ws1Session.getRootNode().addNode("node_101").setProperty("exo:data", new FileInputStream(tempf));
@@ -1226,7 +1225,7 @@
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
- {
+ {
BackupChainLog bchLog = new BackupChainLog(backLog);
assertNotNull(bchLog.getStartedTime());
@@ -1261,12 +1260,12 @@
if (back1 != null)
back1.logout();
}
- }
+ }
else
fail("There are no backup files in " + backDir.getAbsolutePath());
- }
+ }
- public void testExistedWorkspaceRestore() throws Exception
+ public void _testExistedWorkspaceRestoreMultiDB() throws Exception
{
// backup
File backDir = new File("target/backup/" + getUUIndex());
@@ -1317,13 +1316,80 @@
assertNotNull(bchLog.getStartedTime());
assertNotNull(bchLog.getFinishedTime());
- backup.restoreExistingWorkspace(bchLog, repositoryNameToBackup, ws1, false);
+ try
+ {
+ backup.restoreExistingWorkspace(bchLog, repositoryNameToBackup, ws1, false);
+ fail("Exception should be thrown");
+ }
+ catch (WorkspaceRestoreException e)
+ {
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedWorkspaceRestoreSingleDB() throws Exception
+ {
+ SessionImpl ws1Session = (SessionImpl)repositoryService.getRepository("db7").login(credentials, "ws1");
+
+ // backup
+ File backDir = new File("target/backup/" + getUUIndex());
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db7");
+ config.setWorkspace(workspaceNameToBackup);
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup("db7", workspaceNameToBackup);
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (ws1Session.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistingWorkspace(bchLog, "db7", ws1, false);
+
// check
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)getReposityToBackup().login(credentials, "ws1");
+ back1 = (SessionImpl)repositoryService.getRepository("db7").login(credentials, "ws1");
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -1345,6 +1411,9 @@
public void testExistedWorkspaceRestoreAsync() throws Exception
{
+ SessionImpl ws1Session = (SessionImpl)repositoryService.getRepository("db7").login(credentials, "ws1");
+ String repositoryNameToBackup = "db7";
+
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1406,7 +1475,9 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)getReposityToBackup().login(credentials, workspaceNameToBackup);
+ back1 =
+ (SessionImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials,
+ workspaceNameToBackup);
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -1428,6 +1499,9 @@
public void testExistedWorkspaceRestoreAsync2() throws Exception
{
+ SessionImpl ws1Session = (SessionImpl)repositoryService.getRepository("db7").login(credentials, "ws1");
+ String repositoryNameToBackup = "db7";
+
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1489,7 +1563,9 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)getReposityToBackup().login(credentials, workspaceNameToBackup);
+ back1 =
+ (SessionImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials,
+ workspaceNameToBackup);
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -1904,6 +1980,10 @@
public void testExistedWorkspaceRestoreWithConfig() throws Exception
{
+ RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository(repositoryNameToBackupSingleDB);
+ String repositoryNameToBackup = "db7";
+ SessionImpl sessionWS = (SessionImpl)repositoryDB7.login(credentials, workspaceNameToBackup);
+
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -1948,7 +2028,9 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)getReposityToBackup().login(credentials, workspaceNameToBackup);
+ back1 =
+ (SessionImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials,
+ workspaceNameToBackup);
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -2042,6 +2124,9 @@
public void testWorkspaceRestoreWithConfig() throws Exception
{
+ RepositoryImpl repositoryDB7 = (RepositoryImpl)repositoryService.getRepository(repositoryNameToBackupSingleDB);
+ String repositoryNameToBackup = "db7";
+
// backup
File backDir = new File("target/backup/" + getUUIndex());
backDir.mkdirs();
@@ -2072,8 +2157,8 @@
fail("Can't get fullBackup chain");
//TODO
- super.tearDown();
- removeWorkspaceFully(repositoryNameToBackup, workspaceNameToBackup);
+ // super.tearDown();
+ removeWorkspaceFullySingleDB(repositoryNameToBackup, workspaceNameToBackup);
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())
@@ -2089,7 +2174,7 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)getReposityToBackup().login(credentials, "ws1");
+ back1 = (SessionImpl)repositoryService.getRepository(repositoryNameToBackup).login(credentials, "ws1");
Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same", "property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-12-20 09:24:04 UTC (rev 3679)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2010-12-20 09:24:58 UTC (rev 3680)
@@ -483,6 +483,11 @@
<section>
<title>Restore existing workspace or repository</title>
+ <note>
+ <para>Restoring single workspace into existed one in case of multi-db is
+ not supported.</para>
+ </note>
+
<para>The resore of existing workspace or repositry is available.</para>
<para>For restore will be used spacial methods:</para>
13 years, 5 months
exo-jcr SVN: r3679 - in jcr/trunk: exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-20 04:24:04 -0500 (Mon, 20 Dec 2010)
New Revision: 3679
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
Log:
EXOJCR-939: clean data for single workspace in case of multi-db is not supported
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java 2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java 2010-12-20 09:24:04 UTC (rev 3679)
@@ -35,4 +35,15 @@
{
super(message, e);
}
+
+ /**
+ * Constructor DBCleanerException.
+ *
+ * @param message
+ * error message
+ */
+ public DBCleanerException(String message)
+ {
+ super(message);
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2010-12-20 09:24:04 UTC (rev 3679)
@@ -20,6 +20,7 @@
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.core.security.JCRRuntimePermissions;
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;
@@ -58,6 +59,69 @@
*/
public void cleanWorkspaceData(WorkspaceEntry wsEntry) throws DBCleanerException
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+ }
+
+ boolean isMultiDb;
+ try
+ {
+ String multiDb = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+ if (multiDb == null)
+ {
+ throw new RepositoryConfigurationException("Parameter " + JDBCWorkspaceDataContainer.MULTIDB
+ + " not found in workspace configuration " + wsEntry.getName());
+ }
+
+ isMultiDb = Boolean.parseBoolean(multiDb);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new DBCleanerException("Can't define " + JDBCWorkspaceDataContainer.MULTIDB + " parameter", e);
+ }
+
+ if (isMultiDb)
+ {
+ throw new DBCleanerException("Clean of single workspace for multi-db is not supported");
+ }
+
+ getDBCleaner(wsEntry).clean();
+ }
+
+ /**
+ * Cleanup repository data from database.
+ *
+ * @param repoEntry
+ * repository configuration
+ * @throws DBCleanerException
+ * if any exception is occurred
+ */
+ public void cleanRepositoryData(RepositoryEntry repoEntry) throws DBCleanerException
+ {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+ }
+
+ for (WorkspaceEntry wsEntry : repoEntry.getWorkspaceEntries())
+ {
+ getDBCleaner(wsEntry).clean();
+ }
+ }
+
+ /**
+ * Returns DBCleaner for defined workspace.
+ *
+ * @param wsEntry
+ * workspace configuration
+ * @throws DBCleanerException
+ * if any exception is occurred
+ */
+ private DBCleaner getDBCleaner(WorkspaceEntry wsEntry) throws DBCleanerException
+ {
String sourceName;
try
{
@@ -175,23 +239,6 @@
}
}
- // clean data
- dbCleaner.clean();
+ return dbCleaner;
}
-
- /**
- * Cleanup repository data from database.
- *
- * @param repoEntry
- * repository configuration
- * @throws DBCleanerException
- * if any exception is occurred
- */
- public void cleanRepositoryData(RepositoryEntry repoEntry) throws DBCleanerException
- {
- for (WorkspaceEntry wsEntry : repoEntry.getWorkspaceEntries())
- {
- cleanWorkspaceData(wsEntry);
- }
- }
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java 2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java 2010-12-20 09:24:04 UTC (rev 3679)
@@ -23,6 +23,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.util.jdbc.cleaner.DBCleanerException;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
@@ -249,21 +250,18 @@
Statement statement = conn.createStatement();
ResultSet res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
assertTrue(res.next());
+ statement.close();
// remove workspace data from database
- new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
-
- // check - does JCR_SITEM become empty
try
{
- res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
- fail();
+ new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
+ fail("Exception should be thrown");
}
- catch (SQLException e)
+ catch (DBCleanerException e)
{
- //ok
+
}
- statement.close();
service.removeRepository(repositoryName);
}
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml 2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml 2010-12-20 09:24:04 UTC (rev 3679)
@@ -64,30 +64,8 @@
</section>
<section>
- <title>Scripts in detail</title>
+ <title>Limitation</title>
- <para>Single and Multi DB scripts examples</para>
-
- <para>In case of isMultiDB="true", will use:</para>
-
- <programlisting>DROP TABLE JCR_MREF;
-DROP TABLE JCR_MVALUE;
-DROP TABLE JCR_MITEM;</programlisting>
-
- <para>In case of isMultiDB="false", will use:</para>
-
- <programlisting>delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?);
-delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?);
-delete from JCR_SITEM where CONTAINER_NAME=?;</programlisting>
-
- <note>
- <para>"?" will be replased with container name on execution.</para>
- </note>
-
- <para>But some database do not support cascade delete or need special
- sittings, so query "delete from JCR_SITEM where CONTAINER_NAME=?" may
- causes constraint violation exception. In such case will be used deleting
- like visitor does. First traverse to the bottom of the tree and then go up
- to the root and perform deleting children. </para>
+ <para>Clean of single workspace for multi-db is not supported.</para>
</section>
</chapter>
13 years, 5 months
exo-jcr SVN: r3678 - jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-20 03:22:12 -0500 (Mon, 20 Dec 2010)
New Revision: 3678
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
Log:
JCR-1541: SessionDataManager.listChildPropertiesData(NodeData parent) now does not return ValueDatas
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-12-17 11:44:29 UTC (rev 3677)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-12-20 08:22:12 UTC (rev 3678)
@@ -864,7 +864,7 @@
try
{
- return (List<PropertyData>)mergeProps(parent, transactionableManager);
+ return (List<PropertyData>)mergeProps(parent, false, transactionableManager);
}
finally
{
@@ -890,7 +890,7 @@
try
{
- return (List<PropertyData>)mergeProps(parent, transactionableManager);
+ return (List<PropertyData>)mergeProps(parent, true, transactionableManager);
}
finally
{
@@ -1859,9 +1859,11 @@
* from outgoing list WARN. THIS METHOD HAS SIBLING - mergeList, see below.
*
* @param rootData
+ * @param listOnly
* @return
*/
- protected List<? extends ItemData> mergeProps(ItemData rootData, DataManager dataManager) throws RepositoryException
+ protected List<? extends ItemData> mergeProps(ItemData rootData, boolean listOnly, DataManager dataManager)
+ throws RepositoryException
{
// 1 get all transient descendants
Collection<ItemState> transientDescendants = changesLog.getLastChildrenStates(rootData, false);
@@ -1870,7 +1872,7 @@
{
// 2 get ALL persisted descendants
Map<String, ItemData> descendants = new LinkedHashMap<String, ItemData>();
- traverseStoredDescendants(rootData, dataManager, MERGE_PROPS, descendants, false, transientDescendants);
+ traverseStoredDescendants(rootData, dataManager, MERGE_PROPS, descendants, listOnly, transientDescendants);
// merge data
for (ItemState state : transientDescendants)
13 years, 5 months
exo-jcr SVN: r3677 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-17 06:44:29 -0500 (Fri, 17 Dec 2010)
New Revision: 3677
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.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/TesterRdbmsWorkspaceInitializer.java
Log:
EXOJCR-1078: support rollback changes in case of errors
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-17 10:46:17 UTC (rev 3676)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsBackupWorkspaceInitializer.java 2010-12-17 11:44:29 UTC (rev 3677)
@@ -16,6 +16,7 @@
*/
package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
+import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
@@ -27,9 +28,12 @@
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 org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.IOException;
+
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -54,10 +58,11 @@
public RdbmsBackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager);
+ accessManager, repositoryService);
}
/**
@@ -73,11 +78,34 @@
long start = System.currentTimeMillis();
- // restore from full rdbms backup
- fullRdbmsRestore();
+ try
+ {
+ // restore from full rdbms backup
+ fullRdbmsRestore();
- // restore from incremental backup
- incrementalRead();
+ // restore from incremental backup
+ incrementalRead();
+ }
+ catch (Throwable e)
+ {
+ try
+ {
+ rollback();
+ }
+ catch (RepositoryConfigurationException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ catch (DBCleanerException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ catch (IOException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ throw new RepositoryException(e);
+ }
final NodeData root = (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-17 10:46:17 UTC (rev 3676)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-17 11:44:29 UTC (rev 3677)
@@ -20,6 +20,7 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerParams;
@@ -27,12 +28,17 @@
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.core.ManageableRepository;
+import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.ext.backup.impl.IndexCleanHelper;
+import org.exoplatform.services.jcr.ext.backup.impl.ValueStorageCleanHelper;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.BackupWorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
@@ -43,6 +49,8 @@
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.jcr.impl.util.jdbc.cleaner.DBCleanerException;
+import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -83,6 +91,10 @@
*/
protected static final Log log = ExoLogger.getLogger("exo.jcr.component.core.RdbmsWorkspaceInitializer");
+ /**
+ * The repository service.
+ */
+ protected final RepositoryService repositoryService;
/**
* List of temporary files.
@@ -95,10 +107,13 @@
public RdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
accessManager);
+
+ this.repositoryService = repositoryService;
}
/**
@@ -114,7 +129,30 @@
long start = System.currentTimeMillis();
- fullRdbmsRestore();
+ try
+ {
+ fullRdbmsRestore();
+ }
+ catch (Throwable e)
+ {
+ try
+ {
+ rollback();
+ }
+ catch (RepositoryConfigurationException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ catch (DBCleanerException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ catch (IOException e1)
+ {
+ throw new RepositoryException("Can't rollback changes", e);
+ }
+ throw new RepositoryException(e);
+ }
final NodeData root = (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
@@ -278,18 +316,6 @@
}
catch (SQLException e)
{
- if (jdbcConn != null)
- {
- try
- {
- jdbcConn.rollback();
- }
- catch (SQLException e1)
- {
- log.error("Rollback error", e1);
- }
- }
-
SQLException next = e.getNextException();
String errorTrace = "";
while (next != null)
@@ -392,13 +418,57 @@
/**
* Rollback changes due to errors.
+ *
+ * @throws RepositoryConfigurationException
+ * @throws RepositoryException
+ * @throws DBCleanerException
+ * @throws IOException
*/
- protected void rollback(Connection jdbcConn)
+ protected void rollback() throws RepositoryException, RepositoryConfigurationException, DBCleanerException,
+ IOException
{
- // TODO
+ boolean isSystem =
+ repositoryService.getRepository(repositoryEntry.getName()).getConfiguration().getSystemWorkspaceName()
+ .equals(workspaceEntry.getName());
+
+ //close all session
+ forceCloseSession(repositoryEntry.getName(), workspaceEntry.getName());
+
+ //clean database
+ new DBCleanerService().cleanWorkspaceData(workspaceEntry);
+
+ //clean index
+ new IndexCleanHelper().removeWorkspaceIndex(workspaceEntry, isSystem);
+
+ //clean value storage
+ new ValueStorageCleanHelper().removeWorkspaceValueStorage(workspaceEntry);
}
/**
+ * Close sessions on specific workspace.
+ *
+ * @param repositoryName
+ * repository name
+ * @param workspaceName
+ * workspace name
+ * @return int return the how many sessions was closed
+ * @throws RepositoryConfigurationException
+ * will be generate RepositoryConfigurationException
+ * @throws RepositoryException
+ * will be generate RepositoryException
+ */
+ private int forceCloseSession(String repositoryName, String workspaceName) throws RepositoryException,
+ RepositoryConfigurationException
+ {
+ ManageableRepository mr = repositoryService.getRepository(repositoryName);
+ WorkspaceContainerFacade wc = mr.getWorkspaceContainer(workspaceName);
+
+ SessionRegistry sessionRegistry = (SessionRegistry)wc.getComponent(SessionRegistry.class);
+
+ return sessionRegistry.closeSessions(workspaceName);
+ }
+
+ /**
* Restoring value storage from backup.
*/
protected void restoreValueStorage() throws RepositoryConfigurationException, IOException
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-17 10:46:17 UTC (rev 3676)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2010-12-17 11:44:29 UTC (rev 3677)
@@ -91,7 +91,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
- (ValueFactoryImpl)valueFactory, null);
+ (ValueFactoryImpl)valueFactory, null, repositoryService);
initializer.restoreValueFiles();
assertTrue(new File(newValueStoragePath).list().length > 0);
@@ -146,7 +146,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
- (ValueFactoryImpl)valueFactory, null);
+ (ValueFactoryImpl)valueFactory, null, repositoryService);
initializer.restoreValueFiles();
assertFalse(new File(newValueStoragePath).exists());
@@ -217,7 +217,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(), cacheableDataManager, null, null, null,
- (ValueFactoryImpl)valueFactory, null);
+ (ValueFactoryImpl)valueFactory, null, repositoryService);
// restore multi -> multi
initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
@@ -262,7 +262,7 @@
initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
// restore multi -> single
initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
@@ -334,7 +334,7 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
// restore single -> multi
initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
@@ -379,7 +379,7 @@
initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null);
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService);
// restore single -> single
initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2010-12-17 10:46:17 UTC (rev 3676)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2010-12-17 11:44:29 UTC (rev 3677)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -52,10 +53,11 @@
public TesterRdbmsWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl namespaceRegistry,
LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager, ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
+ AccessManager accessManager, RepositoryService repositoryService) throws RepositoryConfigurationException,
+ PathNotFoundException, RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
- accessManager);
+ accessManager, repositoryService);
}
public void restoreValueFiles() throws RepositoryConfigurationException, IOException
13 years, 5 months
exo-jcr SVN: r3676 - 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-17 05:46:17 -0500 (Fri, 17 Dec 2010)
New Revision: 3676
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/RdbmsWorkspaceInitializer.java
Log:
EXOJCR-1090: zip content
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-17 10:45:11 UTC (rev 3675)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-17 10:46:17 UTC (rev 3676)
@@ -26,7 +26,6 @@
import org.exoplatform.services.jcr.config.ValueStorageEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
@@ -34,7 +33,7 @@
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
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;
@@ -47,7 +46,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -58,6 +56,8 @@
import java.sql.Types;
import java.util.Calendar;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
@@ -73,48 +73,28 @@
/**
* Index directory in full backup storage.
*/
- public static final String INDEX_DIR = "index";
+ 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;
+ /**
+ * 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";
+ /**
+ * 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 file.
+ */
+ public static final String CONTENT_FILE_SUFFIX = ".dump";
- /**
- * Suffix for content length file.
- */
- public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
+ /**
+ * Suffix for content length file.
+ */
+ 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;
-
/**
* Logger.
*/
@@ -423,17 +403,19 @@
{
int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
- ObjectWriter contentWriter = null;
- ObjectWriter contentLenWriter = null;
+ ObjectZipWriterImpl contentWriter = null;
+ ObjectZipWriterImpl contentLenWriter = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
File contentFile = new File(getStorageURL().getFile(), tableName + CONTENT_FILE_SUFFIX);
- contentWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentFile));
+ contentWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
+ contentWriter.putNextEntry(new ZipEntry(tableName));
File contentLenFile = new File(getStorageURL().getFile(), tableName + CONTENT_LEN_FILE_SUFFIX);
- contentLenWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentLenFile));
+ contentLenWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
+ contentLenWriter.putNextEntry(new ZipEntry(tableName));
stmt = jdbcConn.prepareStatement(script);
rs = stmt.executeQuery();
@@ -475,7 +457,7 @@
if (value == null)
{
- contentLenWriter.writeByte(NULL_LEN);
+ contentLenWriter.writeLong(-1);
}
else
{
@@ -488,7 +470,7 @@
contentWriter.write(tmpBuff, 0, read);
len += read;
}
- writeCompressedContentLen(contentLenWriter, len);
+ contentLenWriter.writeLong(len);
}
}
}
@@ -497,11 +479,13 @@
{
if (contentWriter != null)
{
+ contentWriter.closeEntry();
contentWriter.close();
}
if (contentLenWriter != null)
{
+ contentLenWriter.closeEntry();
contentLenWriter.close();
}
@@ -518,28 +502,6 @@
}
/**
- * Write content length in output.
- */
- private void writeCompressedContentLen(ObjectWriter out, long len) throws IOException
- {
- if (len < Byte.MAX_VALUE)
- {
- out.writeByte(BYTE_LEN);
- out.writeByte((byte)len);
- }
- else if (len < Integer.MAX_VALUE)
- {
- out.writeByte(INT_LEN);
- out.writeInt((int)len);
- }
- else
- {
- out.writeByte(LONG_LEN);
- out.writeLong(len);
- }
- }
-
- /**
* {@inheritDoc}
*/
public void stop()
@@ -575,12 +537,13 @@
else
{
InputStream in = null;
- OutputStream out = null;
+ ZipOutputStream out = null;
try
{
in = PrivilegedFileHelper.fileInputStream(srcPath);
- out = PrivilegedFileHelper.fileOutputStream(dstPath);
+ out = PrivilegedFileHelper.zipOutputStream(dstPath);
+ out.putNextEntry(new ZipEntry(srcPath.getName()));
// Transfer bytes from in to out
byte[] buf = new byte[2048];
@@ -601,6 +564,7 @@
if (out != null)
{
+ out.closeEntry();
out.close();
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-17 10:45:11 UTC (rev 3675)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2010-12-17 10:46:17 UTC (rev 3676)
@@ -38,7 +38,7 @@
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.dataflow.serialization.ObjectZipReaderImpl;
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;
@@ -63,6 +63,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.zip.ZipInputStream;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -468,12 +469,13 @@
}
else
{
- InputStream in = null;
+ ZipInputStream in = null;
OutputStream out = null;
try
{
- in = PrivilegedFileHelper.fileInputStream(srcPath);
+ in = PrivilegedFileHelper.zipInputStream(srcPath);
+ in.getNextEntry();
out = PrivilegedFileHelper.fileOutputStream(dstPath);
// Transfer bytes from in to out
@@ -509,8 +511,8 @@
{
String insertNodeQuery = null;
- ObjectReader contentReader = null;
- ObjectReader contentLenReader = null;
+ ObjectZipReaderImpl contentReader = null;
+ ObjectZipReaderImpl contentLenReader = null;
PreparedStatement insertNode = null;
ResultSet tableMetaData = null;
@@ -519,9 +521,12 @@
try
{
- contentReader = new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(helper.contentFile));
- contentLenReader = new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(helper.contentLenFile));
+ contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentFile()));
+ contentReader.getNextEntry();
+ contentLenReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentLenFile()));
+ contentLenReader.getNextEntry();
+
// get information about backup table
int sourceColumnCount = contentReader.readInt();
@@ -592,7 +597,7 @@
{
try
{
- len = readCompressedContentLen(contentLenReader);
+ len = contentLenReader.readLong();
}
catch (EOFException e)
{
@@ -611,7 +616,7 @@
throw new IOException("Content length file is empty but content still present", e);
}
- stream = spoolInputStream(contentReader, len);
+ stream = len == -1 ? null : spoolInputStream(contentReader, len);
}
if (helper.getSkipColumnIndex() != null && helper.getSkipColumnIndex() == i)
@@ -623,57 +628,58 @@
targetIndex--;
continue;
}
- else if (helper.getConvertColumnIndexes().contains(i))
- {
- // convert column value
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
- String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
- if (currentValue.equals(Constants.ROOT_PARENT_UUID))
+ // set
+ if (stream != null)
+ {
+ if (helper.getConvertColumnIndexes().contains(i))
{
- stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
- }
- else
- {
- if (helper.isMultiDb)
+ // convert column value
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
+ if (currentValue.equals(Constants.ROOT_PARENT_UUID))
{
- if (!helper.isBackupMutliDb())
- {
- stream =
- new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
- helper.getBackupWorkspaceName().length()).getBytes());
- }
+ stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
}
else
{
- if (helper.isBackupMutliDb())
+ if (helper.isMultiDb)
{
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(currentValue);
-
- stream = new ByteArrayInputStream(builder.toString().getBytes());
+ if (!helper.isBackupMutliDb())
+ {
+ stream =
+ new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
+ helper.getBackupWorkspaceName().length()).getBytes());
+ }
}
else
{
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(helper
- .getBackupWorkspaceName().length()));
+ if (helper.isBackupMutliDb())
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(workspaceName);
+ builder.append(currentValue);
- stream = new ByteArrayInputStream(builder.toString().getBytes());
+ stream = new ByteArrayInputStream(builder.toString().getBytes());
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(workspaceName);
+ builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(helper
+ .getBackupWorkspaceName().length()));
+
+ stream = new ByteArrayInputStream(builder.toString().getBytes());
+ }
}
}
+
+ len = ((ByteArrayInputStream)stream).available();
}
- len = ((ByteArrayInputStream)stream).available();
- }
-
- // set
- if (len != FullBackupJob.NULL_LEN)
- {
if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
|| columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
{
@@ -769,31 +775,6 @@
}
/**
- * Write content length in output.
- */
- private long readCompressedContentLen(ObjectReader in) throws IOException
- {
- byte lenType = in.readByte();
-
- if (lenType == FullBackupJob.NULL_LEN)
- {
- return lenType;
- }
- else if (lenType == FullBackupJob.BYTE_LEN)
- {
- return in.readByte();
- }
- else if (lenType == FullBackupJob.INT_LEN)
- {
- return in.readInt();
- }
- else
- {
- throw new RuntimeException("Does not support to restore value more than 2G.");
- }
- }
-
- /**
* Spool input stream.
*/
private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
13 years, 5 months
exo-jcr SVN: r3675 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-17 05:45:11 -0500 (Fri, 17 Dec 2010)
New Revision: 3675
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipReaderImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipWriterImpl.java
Log:
EXOJCR-1090: add ObjectZipReaderImpl and ObjectZipWriterImpl
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipReaderImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipReaderImpl.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipReaderImpl.java 2010-12-17 10:45:11 UTC (rev 3675)
@@ -0,0 +1,62 @@
+/*
+ * 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.dataflow.serialization;
+
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 13.02.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: ObjectZipReaderImpl 111 2008-11-11 11:11:11Z rainf0x $
+ */
+public class ObjectZipReaderImpl extends ObjectReaderImpl
+{
+
+ /**
+ * The ZipInputStream
+ */
+ private final ZipInputStream in;
+
+ /**
+ * ObjectZipReaderImpl constructor.
+ *
+ * @param in
+ * original InputStream
+ */
+ public ObjectZipReaderImpl(ZipInputStream in)
+ {
+ super(in);
+ this.in = in;
+ }
+
+ /**
+ * Get next ZipEntry.
+ *
+ * @return
+ * @throws IOException
+ */
+ public ZipEntry getNextEntry() throws IOException
+ {
+ return this.in.getNextEntry();
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipWriterImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipWriterImpl.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/ObjectZipWriterImpl.java 2010-12-17 10:45:11 UTC (rev 3675)
@@ -0,0 +1,79 @@
+/*
+ * 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.dataflow.serialization;
+
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Created by The eXo Platform SAS. <br/>
+ * Date: 13.02.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: ObjectZipWriterImpl 111 2008-11-11 11:11:11Z rainf0x $
+ */
+public class ObjectZipWriterImpl extends ObjectWriterImpl
+{
+
+ /**
+ * ZipOutputStream.
+ */
+ private final ZipOutputStream out;
+
+ /**
+ * ObjectZipWriterImpl constructor.
+ *
+ * @param out
+ * the ZipOutputStream.
+ * @throws IOException
+ * if any errors occurred
+ */
+ public ObjectZipWriterImpl(ZipOutputStream out)
+ {
+ super(out);
+ this.out = out;
+ }
+
+ /**
+ * Put next entry.
+ *
+ * @param zipEntry
+ * the zipEntry
+ * @throws IOException
+ * if any errors occurred
+ */
+ public void putNextEntry(ZipEntry zipEntry) throws IOException
+ {
+ this.out.putNextEntry(zipEntry);
+ }
+
+ /**
+ * Close current entry.
+ *
+ * @throws IOException
+ * if any errors occurred
+ */
+ public void closeEntry() throws IOException
+ {
+ flush();
+ this.out.closeEntry();
+ }
+
+}
13 years, 5 months
exo-jcr SVN: r3674 - jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-12-17 04:00:38 -0500 (Fri, 17 Dec 2010)
New Revision: 3674
Modified:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-1080 : Avoid Doc's transfer if current JCR-node is RW.
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-17 08:42:48 UTC (rev 3673)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-17 09:00:38 UTC (rev 3674)
@@ -815,7 +815,8 @@
private void updateInternal(final Collection<String> remove, final Collection<Document> add) throws IOException
{
- if (rpcService == null)
+ // if RPC not configured or current node is in READ_WRITE mode
+ if (rpcService == null || modeHandler.getMode() == IndexerIoMode.READ_WRITE)
{
index.update(remove, add);
}
13 years, 5 months
exo-jcr SVN: r3673 - in jcr/branches/1.14-IMPR/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/impl and 5 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-12-17 03:42:48 -0500 (Fri, 17 Dec 2010)
New Revision: 3673
Modified:
jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SingletonTokenStream.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-configuration.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-1080 : First "quick and dirty" POC implementation of Indexer, where documents are created on client side and then sent to coordinator.
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-17 08:42:48 UTC (rev 3673)
@@ -380,7 +380,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
@@ -433,7 +432,8 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/TestLinkedWorkspaceStorageCacheMetrics.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestLockPerstistentDataManager.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestCleanableFileStreamValueData.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/impl/**/TestCleanableFileStreamValueData.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/impl/**/TestSecurityRepositoryManagment.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -580,7 +580,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TAKE CARE TO UPDATE ALSO run-all PROFILE -->
- <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
@@ -657,7 +656,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TAKE CARE TO UPDATE ALSO run-tck PROFILE -->
- <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
@@ -738,6 +736,7 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestCleanableFileStreamValueData.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestLockPerstistentDataManager.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/impl/**/TestSecurityRepositoryManagment.java</exclude>
<!-- From TCK -->
<exclude>org/apache/jackrabbit/test/api/TestAll.java</exclude>
<exclude>org/apache/jackrabbit/test/api/**/Abstract*.java</exclude>
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -35,6 +35,7 @@
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rpc.RPCService;
import org.picocontainer.Startable;
import java.io.InputStream;
@@ -90,13 +91,22 @@
currentRepositoryName.set(config.getDefaultRepositoryName());
managerStartChanges = new ManagerStartChanges();
}
+
+ public RepositoryServiceImpl(RepositoryServiceConfiguration configuration, ExoContainerContext context, RPCService rpcService)
+ {
+ this(configuration, context);
+ }
public void addPlugin(ComponentPlugin plugin)
{
if (plugin instanceof AddNodeTypePlugin)
+ {
addNodeTypePlugins.add(plugin);
+ }
else if (plugin instanceof AddNamespacesPlugin)
+ {
addNamespacesPlugins.add(plugin);
+ }
else if (plugin instanceof RepositoryChangesListenerRegisterPlugin)
{
managerStartChanges.addPlugin((RepositoryChangesListenerRegisterPlugin)plugin);
@@ -167,7 +177,9 @@
public ManageableRepository getCurrentRepository() throws RepositoryException
{
if (currentRepositoryName.get() == null)
+ {
return getDefaultRepository();
+ }
return getRepository(currentRepositoryName.get());
}
@@ -192,7 +204,9 @@
RepositoryContainer repositoryContainer = repositoryContainers.get(name);
log.debug("RepositoryServiceimpl() getRepository " + name);
if (repositoryContainer == null)
+ {
throw new RepositoryException("Repository '" + name + "' not found.");
+ }
return (ManageableRepository)repositoryContainer.getComponentInstanceOfType(ManageableRepository.class);
}
@@ -208,7 +222,9 @@
public void setCurrentRepositoryName(String repositoryName) throws RepositoryConfigurationException
{
if (!repositoryContainers.containsKey(repositoryName))
+ {
throw new RepositoryConfigurationException("Repository is not configured. Name " + repositoryName);
+ }
currentRepositoryName.set(repositoryName);
}
@@ -352,8 +368,10 @@
private void removeRepository(String name, boolean allowRemoveDefaultRepository) throws RepositoryException
{
if (!canRemoveRepository(name, allowRemoveDefaultRepository))
+ {
throw new RepositoryException("Repository " + name + " in use. If you want to "
+ " remove repository close all open sessions");
+ }
try
{
@@ -407,14 +425,18 @@
{
// Check non system workspaces
if (!repo.getSystemWorkspaceName().equals(wsEntry.getName()) && !repo.canRemoveWorkspace(wsEntry.getName()))
+ {
return false;
+ }
}
// check system workspace
RepositoryContainer repositoryContainer = repositoryContainers.get(name);
SessionRegistry sessionRegistry =
(SessionRegistry)repositoryContainer.getComponentInstance(SessionRegistry.class);
if (sessionRegistry == null || sessionRegistry.isInUse(repo.getSystemWorkspaceName()))
+ {
return false;
+ }
}
catch (RepositoryConfigurationException e)
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -54,6 +54,7 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rpc.RPCService;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.picocontainer.Startable;
@@ -140,7 +141,9 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
+
+ protected final RPCService rpcService;
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -165,10 +168,11 @@
* @throws RepositoryConfigurationException
*/
- public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
- WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
- DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
- throws RepositoryException, RepositoryConfigurationException
+ public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg,
+ NodeTypeDataManager ntReg, WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
+ DocumentReaderService extractor, ConfigurationManager cfm,
+ final RepositoryIndexSearcherHolder indexSearcherHolder, RPCService rpcService) throws RepositoryException,
+ RepositoryConfigurationException
{
this.wsId = wsConfig.getUniqueName();
this.extractor = extractor;
@@ -180,6 +184,7 @@
this.cfm = cfm;
this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
+ this.rpcService = rpcService;
if (parentSearchManager != null)
{
((WorkspacePersistentDataManager)this.itemMgr).addItemPersistenceListener(this);
@@ -277,7 +282,9 @@
try
{
if (reader != null)
+ {
reader.close();
+ }
}
catch (IOException e)
{
@@ -390,7 +397,9 @@
{
if (log.isDebugEnabled())
+ {
log.debug("start");
+ }
try
{
if (indexingTree == null)
@@ -412,7 +421,9 @@
{
ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
if (excludeData != null)
+ {
excludedPath.add(excludeData.getQPath());
+ }
}
catch (RepositoryException e)
{
@@ -429,7 +440,9 @@
{
ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
if (indexingRootDataItem != null && indexingRootDataItem.isNode())
+ {
indexingRootData = (NodeData)indexingRootDataItem;
+ }
}
catch (RepositoryException e)
{
@@ -510,14 +523,20 @@
if (item.isNode())
{
if (!indexingTree.isExcluded(item))
+ {
return (NodeData)item;
+ }
}
else
+ {
log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
+ " found. ");
+ }
}
else
+ {
log.warn("Unable to index node with id " + id + ", node does not exist.");
+ }
}
catch (RepositoryException e)
@@ -708,14 +727,19 @@
// initialize query handler
String className = config.getType();
if (className == null)
+ {
throw new RepositoryConfigurationException("Content hanler configuration fail");
+ }
try
{
Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
- Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
- handler = (QueryHandler)constuctor.newInstance(config, cfm);
+ Constructor constuctor =
+ qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class, RPCService.class,
+ String.class);
QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
+ handler =
+ (QueryHandler)constuctor.newInstance(config, cfm, rpcService, wsId + (parentHandler != null ? "" : "-sys"));
QueryHandlerContext context = createQueryHandlerContext(parentHandler);
handler.setContext(context);
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -29,6 +29,7 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rpc.RPCService;
import java.util.ArrayList;
import java.util.List;
@@ -57,11 +58,12 @@
public static final String INDEX_DIR_SUFFIX = "system";
- public SystemSearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
- WorkspacePersistentDataManager itemMgr, DocumentReaderService service, ConfigurationManager cfm,
- RepositoryIndexSearcherHolder indexSearcherHolder) throws RepositoryException, RepositoryConfigurationException
+ public SystemSearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg,
+ NodeTypeDataManager ntReg, WorkspacePersistentDataManager itemMgr, DocumentReaderService service,
+ ConfigurationManager cfm, RepositoryIndexSearcherHolder indexSearcherHolder, RPCService rpcService)
+ throws RepositoryException, RepositoryConfigurationException
{
- super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder);
+ super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder, rpcService);
}
@Override
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -189,18 +189,66 @@
protected void doUpdateIndex(Set<String> removedNodes, Set<String> addedNodes, Set<String> parentRemovedNodes,
Set<String> parentAddedNodes)
{
- String id = IdGenerator.generate();
+
+
try
{
- PrivilegedCacheHelper.put(cache, Fqn.fromRelativeElements(rootFqn, id), LISTWRAPPER,
- new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes));
+ searchManager.updateIndex(removedNodes, addedNodes);
}
- catch (CacheException e)
+ catch (RepositoryException e)
{
- log.error(e.getLocalizedMessage(), e);
- logErrorChanges(handler, removedNodes, addedNodes);
- logErrorChanges(parentHandler, parentRemovedNodes, parentAddedNodes);
+ log.error("Error indexing changes " + e, e);
}
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+
+ try
+ {
+ parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ parentHandler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+
+
+
+
+
+// String id = IdGenerator.generate();
+// try
+// {
+// PrivilegedCacheHelper.put(cache, Fqn.fromRelativeElements(rootFqn, id), LISTWRAPPER,
+// new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes));
+// }
+// catch (CacheException e)
+// {
+// log.error(e.getLocalizedMessage(), e);
+// logErrorChanges(handler, removedNodes, addedNodes);
+// logErrorChanges(parentHandler, parentRemovedNodes, parentAddedNodes);
+// }
}
/**
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -878,15 +878,48 @@
* @param value the reader value.
* @return a lucene field.
*/
- protected Fieldable createFulltextField(Reader value)
+ protected Fieldable createFulltextField(Reader reader)
{
+
+ StringBuffer textExtract = new StringBuffer();
+ char[] buffer = new char[1024];
+ int len;
+ try
+ {
+ while ((len = reader.read(buffer)) > -1)
+ {
+ textExtract.append(buffer, 0, len);
+ }
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception reading value for field: " + e.getMessage());
+ log.debug("Dump:", e);
+ }
+ finally
+ {
+ //IOUtils.closeQuietly(reader);
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ }
+ String valueString = textExtract.toString();
+
if (supportHighlighting)
{
- return new LazyTextExtractorField(FieldNames.FULLTEXT, value, true, true);
+ //return new LazyTextExtractorField(FieldNames.FULLTEXT, value, true, true);
+ return new Field(FieldNames.FULLTEXT, valueString, Field.Store.YES, Field.Index.ANALYZED,
+ Field.TermVector.WITH_OFFSETS);
}
else
{
- return new LazyTextExtractorField(FieldNames.FULLTEXT, value, false, false);
+ //return new LazyTextExtractorField(FieldNames.FULLTEXT, value, false, false);
+ return new Field(FieldNames.FULLTEXT, valueString, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO);
}
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -16,6 +16,8 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.collection.TransformedCollection;
@@ -62,6 +64,13 @@
import org.exoplatform.services.jcr.impl.util.SecurityHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.rpc.RPCException;
+import org.exoplatform.services.rpc.RPCService;
+import org.exoplatform.services.rpc.RemoteCommand;
+import org.exoplatform.services.rpc.TopologyChangeEvent;
+import org.exoplatform.services.rpc.TopologyChangeListener;
+import org.exoplatform.services.rpc.impl.RPCServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
@@ -71,6 +80,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -81,7 +91,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Random;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.jcr.RepositoryException;
import javax.jcr.query.InvalidQueryException;
@@ -452,19 +464,27 @@
private final ConfigurationManager cfm;
+ private final RPCService rpcService;
+
+ private final String wsId;
+
+ private RemoteCommand sendDocs;
+
/**
* Working constructor.
*
* @throws RepositoryConfigurationException
* @throws IOException
*/
- public SearchIndex(QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm) throws IOException,
- RepositoryConfigurationException
+ public SearchIndex(QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm, RPCService rpcService, String wsId)
+ throws IOException, RepositoryConfigurationException
{
this.analyzer = new JcrStandartAnalyzer();
// this.queryHandlerConfig = new QueryHandlerEntryWrapper(
// queryHandlerConfig);
this.cfm = cfm;
+ this.rpcService = rpcService;
+ this.wsId = wsId;
SearchIndexConfigurationHelper searchIndexConfigurationHelper = new SearchIndexConfigurationHelper(this);
searchIndexConfigurationHelper.init(queryHandlerConfig);
}
@@ -477,6 +497,8 @@
this.analyzer = new JcrStandartAnalyzer();
// this.queryHandlerConfig = null;
this.cfm = null;
+ this.rpcService = null;
+ this.wsId = null;
}
/**
@@ -627,6 +649,31 @@
}
modeHandler.addIndexerIoModeListener(this);
+
+ // register the command
+ sendDocs = rpcService.registerCommand(new RemoteCommand()
+ {
+ public String getId()
+ {
+ return "sendDocs-" + wsId;
+ }
+
+ public Serializable execute(Serializable[] args) throws Throwable
+ {
+ // additional check! if to JCR nodes are launched on same machine,
+ // RPCService will call this task on both instances.
+ //if (rpcService.isCoordinator())
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ ArrayList<String> remove = (ArrayList<String>)args[0];
+ ArrayList<Document> add = (ArrayList<Document>)args[1];
+ index.update(remove, add);
+ }
+ return null;
+ }
+ });
+ log.info("COMMAND '" + sendDocs.getId() + "' REGISTERED!");
+
}
/**
@@ -699,7 +746,7 @@
final Set<String> removedNodeIds = new HashSet<String>();
final Set<String> addedNodeIds = new HashSet<String>();
- index.update(IteratorUtils.toList(new TransformIterator(remove, new Transformer()
+ updateInternal(IteratorUtils.toList(new TransformIterator(remove, new Transformer()
{
public Object transform(Object input)
{
@@ -762,10 +809,39 @@
}
});
modified.addAll(aggregateRoots.values());
- index.update(aggregateRoots.keySet(), modified);
+ updateInternal(aggregateRoots.keySet(), modified);
}
}
+ private void updateInternal(final Collection<String> remove, final Collection<Document> add) throws IOException
+ {
+ if (rpcService == null)
+ {
+ index.update(remove, add);
+ }
+ else
+ {
+ ArrayList<String> removeList = new ArrayList<String>(remove);
+ ArrayList<Document> addList = new ArrayList<Document>(add);
+ //log.info("sending docs to coordinator");
+ try
+ {
+ rpcService.executeCommandOnCoordinator(sendDocs, true, removeList, addList);
+ }
+ catch (SecurityException e)
+ {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+ catch (RPCException e)
+ {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ }
+
/**
* Creates a new query by specifying the query statement itself and the
* language in which the query is stated. If the query statement is
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SingletonTokenStream.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SingletonTokenStream.java 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SingletonTokenStream.java 2010-12-17 08:42:48 UTC (rev 3673)
@@ -16,64 +16,78 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import java.io.IOException;
-
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.index.Payload;
+import java.io.IOException;
+import java.io.Serializable;
+
/**
* <code>SingletonTokenStream</code> implements a token stream that wraps a
* single value with a given property type. The property type is stored as a
* payload on the single returned token.
*/
-public final class SingletonTokenStream extends TokenStream {
+public final class SingletonTokenStream extends TokenStream implements Serializable
+{
- /**
- * The string value of the token.
- */
- private String value;
+ /**
+ * The string value of the token.
+ */
+ private String value;
- /**
- * The payload of the token.
- */
- private final Payload payload;
+ /**
+ * The payload of the token.
+ */
+ private Payload payload;
- /**
- * Creates a new SingleTokenStream with the given value and a property
- * <code>type</code>.
- *
- * @param value the string value that will be returned with the token.
- * @param type the JCR property type.
- */
- public SingletonTokenStream(String value, int type) {
- this.value = value;
- this.payload = new Payload(new PropertyMetaData(type).toByteArray());
- }
+ /**
+ * for serialization
+ */
+ public SingletonTokenStream()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * Creates a new SingleTokenStream with the given token.
- *
- * @param t the token.
- */
- public SingletonTokenStream(Token t) {
- this.value = t.term();
- this.payload = t.getPayload();
- }
+ /**
+ * Creates a new SingleTokenStream with the given value and a property
+ * <code>type</code>.
+ *
+ * @param value the string value that will be returned with the token.
+ * @param type the JCR property type.
+ */
+ public SingletonTokenStream(String value, int type)
+ {
+ this.value = value;
+ this.payload = new Payload(new PropertyMetaData(type).toByteArray());
+ }
- /**
- * {@inheritDoc}
- */
- public Token next(Token reusableToken) throws IOException {
- if (value == null) {
- return null;
- }
- reusableToken.clear();
- reusableToken.setTermBuffer(value);
- reusableToken.setPayload(payload);
- reusableToken.setStartOffset(0);
- reusableToken.setEndOffset(value.length());
- value = null;
- return reusableToken;
- }
+ /**
+ * Creates a new SingleTokenStream with the given token.
+ *
+ * @param t the token.
+ */
+ public SingletonTokenStream(Token t)
+ {
+ this.value = t.term();
+ this.payload = t.getPayload();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Token next(Token reusableToken) throws IOException
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ reusableToken.clear();
+ reusableToken.setTermBuffer(value);
+ reusableToken.setPayload(payload);
+ reusableToken.setStartOffset(0);
+ reusableToken.setEndOffset(value.length());
+ value = null;
+ return reusableToken;
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-configuration.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-configuration.xml 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-configuration.xml 2010-12-17 08:42:48 UTC (rev 3673)
@@ -101,6 +101,33 @@
</init-params>
</component>
+
+ <component>
+ <key>org.exoplatform.services.rpc.RPCService</key>
+ <type>org.exoplatform.services.rpc.impl.RPCServiceImpl</type>
+ <init-params>
+ <value-param>
+ <name>jgroups-configuration</name>
+ <value>classpath:/udp.xml</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-cluster-name</name>
+ <value>RPCService-Cluster</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-default-timeout</name>
+ <value>0</value>
+ </value-param>
+ <value-param>
+ <name>allow-failover</name>
+ <value>true</value>
+ </value-param>
+ <value-param>
+ <name>retry-timeout</name>
+ <value>20000</value>
+ </value-param>
+ </init-params>
+ </component>
<component>
<key>org.exoplatform.services.jcr.RepositoryService</key>
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-12-17 08:42:48 UTC (rev 3673)
@@ -55,7 +55,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws" />
<property name="changesfilter-class"
@@ -119,7 +119,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws1" />
<property name="changesfilter-class"
@@ -193,7 +193,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws2" />
<property name="changesfilter-class"
@@ -281,7 +281,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws3" />
<property name="changesfilter-class"
@@ -374,7 +374,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws" />
<property name="changesfilter-class"
@@ -455,7 +455,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws1" />
<property name="changesfilter-class"
@@ -534,7 +534,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws2" />
<property name="changesfilter-class"
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-17 07:53:15 UTC (rev 3672)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-17 08:42:48 UTC (rev 3673)
@@ -102,6 +102,34 @@
</init-params>
</component>
+
+ <component>
+ <key>org.exoplatform.services.rpc.RPCService</key>
+ <type>org.exoplatform.services.rpc.impl.RPCServiceImpl</type>
+ <init-params>
+ <value-param>
+ <name>jgroups-configuration</name>
+ <value>classpath:/udp.xml</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-cluster-name</name>
+ <value>RPCService-Cluster</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-default-timeout</name>
+ <value>0</value>
+ </value-param>
+ <value-param>
+ <name>allow-failover</name>
+ <value>true</value>
+ </value-param>
+ <value-param>
+ <name>retry-timeout</name>
+ <value>20000</value>
+ </value-param>
+ </init-params>
+ </component>
+
<component>
<key>org.exoplatform.services.jcr.RepositoryService</key>
<type>org.exoplatform.services.jcr.impl.RepositoryServiceImpl</type>
13 years, 5 months
exo-jcr SVN: r3672 - ws/trunk/exo.ws.frameworks.json/src/main/java/org/exoplatform/ws/frameworks/json/value/impl.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-12-17 02:53:15 -0500 (Fri, 17 Dec 2010)
New Revision: 3672
Modified:
ws/trunk/exo.ws.frameworks.json/src/main/java/org/exoplatform/ws/frameworks/json/value/impl/BooleanValue.java
Log:
EXOJCR-1109
Modified: ws/trunk/exo.ws.frameworks.json/src/main/java/org/exoplatform/ws/frameworks/json/value/impl/BooleanValue.java
===================================================================
--- ws/trunk/exo.ws.frameworks.json/src/main/java/org/exoplatform/ws/frameworks/json/value/impl/BooleanValue.java 2010-12-16 15:32:54 UTC (rev 3671)
+++ ws/trunk/exo.ws.frameworks.json/src/main/java/org/exoplatform/ws/frameworks/json/value/impl/BooleanValue.java 2010-12-17 07:53:15 UTC (rev 3672)
@@ -47,6 +47,15 @@
* {@inheritDoc}
*/
@Override
+ public String getStringValue()
+ {
+ return value ? "true" : "false";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isBoolean()
{
return true;
@@ -58,7 +67,7 @@
@Override
public String toString()
{
- return value ? "true" : "false";
+ return getStringValue();
}
/**
13 years, 5 months
exo-jcr SVN: r3671 - kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-16 10:32:54 -0500 (Thu, 16 Dec 2010)
New Revision: 3671
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
Log:
EXOJCR-1090: allow to create zipInputStream in privileged mode
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-12-16 15:25:25 UTC (rev 3670)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-12-16 15:32:54 UTC (rev 3671)
@@ -30,6 +30,7 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/**
@@ -235,6 +236,44 @@
/**
* Create FileInputStream in privileged mode.
*
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
+ public static ZipInputStream zipInputStream(final File file) throws FileNotFoundException
+ {
+ PrivilegedExceptionAction<ZipInputStream> action = new PrivilegedExceptionAction<ZipInputStream>()
+ {
+ public ZipInputStream run() throws Exception
+ {
+ return new ZipInputStream(new FileInputStream(file));
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof FileNotFoundException)
+ {
+ throw (FileNotFoundException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
+ * Create FileInputStream in privileged mode.
+ *
* @param name
* @return
* @throws FileNotFoundException
13 years, 5 months