exo-jcr SVN: r3761 - in jcr/branches/1.14-IMPR/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/impl and 6 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-12-31 12:35:02 -0500 (Fri, 31 Dec 2010)
New Revision: 3761
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/IndexerChangesFilter.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.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/ChangesFilterListsWrapper.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.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/ChangesHolder.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/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.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/test-configuration.xml
Log:
EXOJCR-1080: Implementation without the RPCService, any classes that use the RPCService have been reverted.
NB: With the default parameters the build fails due to an OutOffMemory because it consumes a little bit more memory, so we need to allocate to the JVM a little bit more memory
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-31 17:35:02 UTC (rev 3761)
@@ -656,6 +656,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TAKE CARE TO UPDATE ALSO run-tck PROFILE -->
+ <argLine>${env.MAVEN_OPTS}</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -35,7 +35,6 @@
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;
@@ -91,22 +90,13 @@
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);
@@ -177,9 +167,7 @@
public ManageableRepository getCurrentRepository() throws RepositoryException
{
if (currentRepositoryName.get() == null)
- {
return getDefaultRepository();
- }
return getRepository(currentRepositoryName.get());
}
@@ -204,9 +192,7 @@
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);
}
@@ -222,9 +208,7 @@
public void setCurrentRepositoryName(String repositoryName) throws RepositoryConfigurationException
{
if (!repositoryContainers.containsKey(repositoryName))
- {
throw new RepositoryConfigurationException("Repository is not configured. Name " + repositoryName);
- }
currentRepositoryName.set(repositoryName);
}
@@ -368,10 +352,8 @@
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
{
@@ -425,18 +407,14 @@
{
// 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/IndexerChangesFilter.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -109,9 +109,6 @@
*/
public void onSaveItems(ItemStateChangesLog itemStates)
{
-
- long time = System.currentTimeMillis();
-
// nodes that need to be removed from the index.
final Set<String> removedNodes = new HashSet<String>();
// nodes that need to be added to the index.
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
@@ -79,6 +80,23 @@
void updateNodes(Iterator<String> remove, Iterator<NodeData> add) throws RepositoryException, IOException;
/**
+ * Extracts all the changes and returns them as a {@link ChangesHolder} instance
+ * @param remove Iterator of <code>NodeIds</code> of nodes to delete
+ * @param add Iterator of <code>NodeState</code> instance to add to the
+ * index.
+ * @return a {@link ChangesHolder} instance that contains all the changes
+ */
+ ChangesHolder getChanges(Iterator<String> remove, Iterator<NodeData> add);
+
+ /**
+ * Applies the given changes to the indes in an atomic operation
+ * @param changes the changes to apply
+ * @throws RepositoryException if an error occurs while indexing a node.
+ * @throws IOException if an error occurs while updating the index.
+ */
+ void apply(ChangesHolder changes) throws RepositoryException, IOException;
+
+ /**
* Closes this <code>QueryHandler</code> and frees resources attached
* to this handler.
*/
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -43,6 +43,7 @@
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
@@ -54,7 +55,6 @@
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;
@@ -141,9 +141,7 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
- protected final RPCService rpcService;
-
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -168,11 +166,10 @@
* @throws 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
+ public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
+ DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
+ throws RepositoryException, RepositoryConfigurationException
{
this.wsId = wsConfig.getUniqueName();
this.extractor = extractor;
@@ -184,7 +181,6 @@
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);
@@ -282,9 +278,7 @@
try
{
if (reader != null)
- {
reader.close();
- }
}
catch (IOException e)
{
@@ -397,9 +391,7 @@
{
if (log.isDebugEnabled())
- {
log.debug("start");
- }
try
{
if (indexingTree == null)
@@ -421,9 +413,7 @@
{
ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
if (excludeData != null)
- {
excludedPath.add(excludeData.getQPath());
- }
}
catch (RepositoryException e)
{
@@ -440,9 +430,7 @@
{
ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
if (indexingRootDataItem != null && indexingRootDataItem.isNode())
- {
indexingRootData = (NodeData)indexingRootDataItem;
- }
}
catch (RepositoryException e)
{
@@ -497,6 +485,23 @@
public void updateIndex(final Set<String> removedNodes, final Set<String> addedNodes) throws RepositoryException,
IOException
{
+ final ChangesHolder changes = getChanges(removedNodes, addedNodes);
+ apply(changes);
+ }
+
+ public void apply(ChangesHolder changes) throws RepositoryException, IOException
+ {
+ if (handler != null && changes != null && (!changes.getAdd().isEmpty() || !changes.getRemove().isEmpty()))
+ {
+ handler.apply(changes);
+ }
+ }
+
+ /**
+ * Extracts all the changes and returns them as a {@link ChangesHolder} instance
+ */
+ public ChangesHolder getChanges(final Set<String> removedNodes, final Set<String> addedNodes)
+ {
if (handler != null)
{
Iterator<NodeData> addedStates = new Iterator<NodeData>()
@@ -523,20 +528,14 @@
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)
@@ -583,12 +582,12 @@
if (removedNodes.size() > 0 || addedNodes.size() > 0)
{
- handler.updateNodes(removedIds, addedStates);
+ return handler.getChanges(removedIds, addedStates);
}
}
-
+ return null;
}
-
+
protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
throws RepositoryConfigurationException
{
@@ -727,19 +726,14 @@
// 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, RPCService.class,
- String.class);
+ Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
+ handler = (QueryHandler)constuctor.newInstance(config, cfm);
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -29,7 +29,6 @@
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;
@@ -58,12 +57,11 @@
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, RPCService rpcService)
- throws RepositoryException, RepositoryConfigurationException
+ public SystemSearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, DocumentReaderService service, ConfigurationManager cfm,
+ RepositoryIndexSearcherHolder indexSearcherHolder) throws RepositoryException, RepositoryConfigurationException
{
- super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder, rpcService);
+ super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder);
}
@Override
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
+
import java.io.Serializable;
import java.util.Set;
@@ -40,6 +42,10 @@
private Set<String> parentRemovedNodes;
+ private ChangesHolder changes;
+
+ private ChangesHolder parentChanges;
+
/**
* Creates ChangesFilterListsWrapper data class, containing given lists.
*
@@ -56,7 +62,31 @@
this.parentAddedNodes = parentAddedNodes;
this.parentRemovedNodes = parentRemovedNodes;
}
+
+ /**
+ * Creates ChangesFilterListsWrapper data class, containing given lists.
+ */
+ public ChangesFilterListsWrapper(ChangesHolder changes, ChangesHolder parentChanges)
+ {
+ this.changes = changes;
+ this.parentChanges = parentChanges;
+ }
+ public boolean withChanges()
+ {
+ return changes != null || parentChanges != null;
+ }
+
+ public ChangesHolder getChanges()
+ {
+ return changes;
+ }
+
+ public ChangesHolder getParentChanges()
+ {
+ return parentChanges;
+ }
+
public Set<String> getAddedNodes()
{
return addedNodes;
@@ -76,15 +106,4 @@
{
return parentRemovedNodes;
}
-
- public String dump()
- {
- StringBuffer buffer = new StringBuffer();
- buffer.append("\n");
- buffer.append("Added=").append(addedNodes.toString()).append("\n");
- buffer.append("Removed=").append(removedNodes.toString()).append("\n");
- buffer.append("ParentAdded=").append(parentAddedNodes.toString()).append("\n");
- buffer.append("ParentRemoved=").append(parentRemovedNodes.toString());
- return buffer.toString();
- }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -30,6 +31,7 @@
import java.io.IOException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -99,10 +101,14 @@
log.warn("No indexer could be found for the fqn " + name.getParent());
if (log.isDebugEnabled()) log.debug("The current content of the map of indexers is " + indexers);
}
+ else if (wrapper.withChanges())
+ {
+ indexer.updateIndex(wrapper.getChanges(), wrapper.getParentChanges());
+ }
else
{
indexer.updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(), wrapper
- .getParentRemovedNodes());
+ .getParentRemovedNodes());
}
}
finally
@@ -250,7 +256,7 @@
log.error("Error indexing changes " + e, e);
try
{
- parentHandler.logErrorChanges(removedNodes, addedNodes);
+ parentHandler.logErrorChanges(parentRemovedNodes, parentAddedNodes);
}
catch (IOException ioe)
{
@@ -259,5 +265,60 @@
}
}
}
+
+ /**
+ * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
+ */
+ protected void updateIndex(ChangesHolder changes, ChangesHolder parentChanges)
+ {
+ // pass lists to search manager
+ if (searchManager != null && changes != null)
+ {
+ try
+ {
+ searchManager.apply(changes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(new HashSet<String>(changes.getRemove()), new HashSet<String>(changes.getAddIds()));
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ // pass lists to parent search manager
+ if (parentSearchManager != null && parentChanges!= null)
+ {
+ try
+ {
+ parentSearchManager.apply(parentChanges);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ parentHandler.logErrorChanges(new HashSet<String>(parentChanges.getRemove()), new HashSet<String>(parentChanges.getAddIds()));
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ }
}
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -77,22 +77,47 @@
{
Fqn<?> fqn = aChildren.getFqn();
Object value = cache.get(fqn, JBossCacheIndexChangesFilter.LISTWRAPPER);
- if (value != null && value instanceof ChangesFilterListsWrapper)
+ if (value instanceof ChangesFilterListsWrapper)
{
// get wrapper object
ChangesFilterListsWrapper listsWrapper = (ChangesFilterListsWrapper)value;
- // get search manager lists
- addedNodes.addAll(listsWrapper.getAddedNodes());
- removedNodes.addAll(listsWrapper.getRemovedNodes());
- // parent search manager lists
- parentAddedNodes.addAll(listsWrapper.getParentAddedNodes());
- parentRemovedNodes.addAll(listsWrapper.getParentAddedNodes());
- }
+ if (listsWrapper.withChanges())
+ {
+ if (listsWrapper.getChanges() != null)
+ {
+ // get search manager lists
+ addedNodes.addAll(listsWrapper.getChanges().getAddIds());
+ removedNodes.addAll(listsWrapper.getChanges().getRemove());
+ }
+ if (listsWrapper.getParentChanges() != null)
+ {
+ // parent search manager lists
+ parentAddedNodes.addAll(listsWrapper.getParentChanges().getAddIds());
+ parentRemovedNodes.addAll(listsWrapper.getParentChanges().getRemove());
+ }
+ }
+ else
+ {
+ // get search manager lists
+ addedNodes.addAll(listsWrapper.getAddedNodes());
+ removedNodes.addAll(listsWrapper.getRemovedNodes());
+ // parent search manager lists
+ parentAddedNodes.addAll(listsWrapper.getParentAddedNodes());
+ parentRemovedNodes.addAll(listsWrapper.getParentAddedNodes());
+ }
+ }
}
//TODO: recover logic is here, lists are: removedNodes and addedNodes String id = IdGenerator.generate();
String id = IdGenerator.generate();
cache.put(Fqn.fromRelativeElements(wsChildren.getFqn(), id), JBossCacheIndexChangesFilter.LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes,
removedNodes, parentAddedNodes, parentRemovedNodes));
+ // Once we put the merged changes into the cache we can remove other changes from the cache
+ for (NodeSPI aChildren : changes)
+ {
+ // Remove the node from the cache and do it asynchronously
+ cache.getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
+ cache.removeNode(aChildren.getFqn());
+ }
}
if (debugEnabled)
log.debug("in-memory state passed to cache cacheLoader successfully");
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -27,6 +27,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
@@ -189,66 +190,26 @@
protected void doUpdateIndex(Set<String> removedNodes, Set<String> addedNodes, Set<String> parentRemovedNodes,
Set<String> parentAddedNodes)
{
-
-
- try
+
+ ChangesHolder changes = searchManager.getChanges(removedNodes, addedNodes);
+ ChangesHolder parentChanges = parentSearchManager.getChanges(parentRemovedNodes, parentAddedNodes);
+
+ if (changes == null && parentChanges == null)
{
- searchManager.updateIndex(removedNodes, addedNodes);
+ return;
}
- catch (RepositoryException e)
- {
- 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);
- }
- }
-
+ String id = IdGenerator.generate();
try
{
- parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
+ PrivilegedCacheHelper.put(cache, Fqn.fromRelativeElements(rootFqn, id), LISTWRAPPER,
+ new ChangesFilterListsWrapper(changes, parentChanges));
}
- catch (RepositoryException e)
+ catch (CacheException e)
{
- log.error("Error indexing changes " + e, e);
+ log.error(e.getLocalizedMessage(), e);
+ logErrorChanges(handler, removedNodes, addedNodes);
+ logErrorChanges(parentHandler, parentRemovedNodes, parentAddedNodes);
}
- 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/ChangesHolder.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -109,6 +109,27 @@
}
/**
+ * @return the collection of id of lucene document to add
+ */
+ public Collection<String> getAddIds()
+ {
+ Collection<String> ids = new LinkedList<String>();
+ for (Document doc : add)
+ {
+ ids.add(getDocId(doc));
+ }
+ return ids;
+ }
+
+ /**
+ * @return the id of the given lucene doc
+ */
+ public String getDocId(Document doc)
+ {
+ return doc.get(FieldNames.UUID);
+ }
+
+ /**
* {@inheritDoc}
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -62,9 +62,6 @@
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.rpc.RPCException;
-import org.exoplatform.services.rpc.RPCService;
-import org.exoplatform.services.rpc.RemoteCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
@@ -74,7 +71,6 @@
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;
@@ -456,27 +452,19 @@
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, RPCService rpcService, String wsId)
- throws IOException, RepositoryConfigurationException
+ public SearchIndex(QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm) 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);
}
@@ -489,8 +477,6 @@
this.analyzer = new JcrStandartAnalyzer();
// this.queryHandlerConfig = null;
this.cfm = null;
- this.rpcService = null;
- this.wsId = null;
}
/**
@@ -641,30 +627,6 @@
}
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)
- {
- ChangesHolder changes = (ChangesHolder)args[0];
- index.update(changes.getRemove(), changes.getAdd());
- }
- return null;
- }
- });
- log.info("COMMAND '" + sendDocs.getId() + "' REGISTERED!");
-
}
/**
@@ -733,11 +695,28 @@
IOException
{
checkOpen();
+ apply(getChanges(remove, add));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void apply(ChangesHolder changes) throws RepositoryException, IOException
+ {
+ checkOpen();
+ index.update(changes.getRemove(), changes.getAdd());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ChangesHolder getChanges(Iterator<String> remove, Iterator<NodeData> add)
+ {
final Map<String, NodeData> aggregateRoots = new HashMap<String, NodeData>();
final Set<String> removedNodeIds = new HashSet<String>();
final Set<String> addedNodeIds = new HashSet<String>();
- updateInternal(IteratorUtils.toList(new TransformIterator(remove, new Transformer()
+ Collection<String> docIdsToRemove = IteratorUtils.toList(new TransformIterator(remove, new Transformer()
{
public Object transform(Object input)
{
@@ -745,7 +724,8 @@
removedNodeIds.add(uuid);
return uuid;
}
- })), IteratorUtils.toList(new TransformIterator(add, new Transformer()
+ }));
+ Collection<Document> docsToAdd = IteratorUtils.toList(new TransformIterator(add, new Transformer()
{
public Object transform(Object input)
{
@@ -770,7 +750,7 @@
}
return doc;
}
- })));
+ }));
// remove any aggregateRoot nodes that are new
// and therefore already up-to-date
@@ -800,35 +780,14 @@
}
});
modified.addAll(aggregateRoots.values());
- updateInternal(aggregateRoots.keySet(), modified);
+ docIdsToRemove.addAll(aggregateRoots.keySet());
+ docsToAdd.addAll(modified);
}
- }
-
- private void updateInternal(final Collection<String> remove, final Collection<Document> add) throws IOException
- {
- // if RPC not configured or current node is in READ_WRITE mode
- if (rpcService == null || modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ if (docIdsToRemove.isEmpty() && docsToAdd.isEmpty())
{
- index.update(remove, add);
+ return null;
}
- else
- {
- try
- {
- rpcService.executeCommandOnCoordinator(sendDocs, true, new ChangesHolder(remove, add));
- }
- catch (SecurityException e)
- {
- e.printStackTrace();
- throw new IOException(e.getMessage());
- }
- catch (RPCException e)
- {
- e.printStackTrace();
- throw new IOException(e.getMessage());
- }
- }
-
+ return new ChangesHolder(docIdsToRemove, docsToAdd);
}
/**
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java 2010-12-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/SlowQueryHandler.java 2010-12-31 17:35:02 UTC (rev 3761)
@@ -23,9 +23,11 @@
import org.exoplatform.services.jcr.impl.core.query.AbstractQueryHandler;
import org.exoplatform.services.jcr.impl.core.query.ExecutableQuery;
import org.exoplatform.services.jcr.impl.core.query.QueryHandlerContext;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
import java.io.IOException;
+import java.util.Iterator;
import java.util.Set;
import javax.jcr.RepositoryException;
@@ -92,4 +94,16 @@
// TODO Auto-generated method stub
return null;
}
+
+ public void apply(ChangesHolder changes) throws RepositoryException, IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public ChangesHolder getChanges(Iterator<String> remove, Iterator<NodeData> add)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-configuration.xml 2010-12-31 17:35:02 UTC (rev 3761)
@@ -108,7 +108,7 @@
<init-params>
<value-param>
<name>jgroups-configuration</name>
- <value>classpath:/udp.xml</value>
+ <value>udp-mux.xml</value>
</value-param>
<value-param>
<name>jgroups-cluster-name</name>
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-30 18:07:06 UTC (rev 3760)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-31 17:35:02 UTC (rev 3761)
@@ -102,34 +102,6 @@
</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, 4 months
exo-jcr SVN: r3760 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-12-30 13:07:06 -0500 (Thu, 30 Dec 2010)
New Revision: 3760
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
Log:
EXOJCR-1133: The Option "Cache Mode Local" must be set with the PrivilegedAction
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-12-30 17:51:23 UTC (rev 3759)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-12-30 18:07:06 UTC (rev 3760)
@@ -557,11 +557,11 @@
Node<Serializable, Object> node = cache.getRoot().getChild(fqn);
if (node == null)
{
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
PrivilegedAction<Node<Serializable, Object>> action = new PrivilegedAction<Node<Serializable, Object>>()
{
public Node<Serializable, Object> run()
{
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
return cache.getRoot().addChild(fqn);
}
};
13 years, 4 months
exo-jcr SVN: r3759 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-12-30 12:51:23 -0500 (Thu, 30 Dec 2010)
New Revision: 3759
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
Log:
EXOJCR-1133: Bug fixed by calling the method addChild(Fqn) within a PriviledgedAction
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-12-30 12:52:09 UTC (rev 3758)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-12-30 17:51:23 UTC (rev 3759)
@@ -31,8 +31,8 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
+import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
-import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.naming.InitialContextInitializer;
@@ -49,6 +49,7 @@
import java.io.Serializable;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -551,13 +552,20 @@
/**
* Will be created structured node in cache, like /$LOCKS
*/
- private void createStructuredNode(Fqn<String> fqn)
+ private void createStructuredNode(final Fqn<String> fqn)
{
Node<Serializable, Object> node = cache.getRoot().getChild(fqn);
if (node == null)
{
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- node = cache.getRoot().addChild(fqn);
+ PrivilegedAction<Node<Serializable, Object>> action = new PrivilegedAction<Node<Serializable, Object>>()
+ {
+ public Node<Serializable, Object> run()
+ {
+ return cache.getRoot().addChild(fqn);
+ }
+ };
+ node = AccessController.doPrivileged(action);
}
node.setResident(true);
}
13 years, 4 months
exo-jcr SVN: r3758 - 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: nfilotto
Date: 2010-12-30 07:52:09 -0500 (Thu, 30 Dec 2010)
New Revision: 3758
Modified:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java
Log:
EXOJCR-1080: LazyTextExtractorField support added
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java 2010-12-30 11:29:48 UTC (rev 3757)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java 2010-12-30 12:52:09 UTC (rev 3758)
@@ -21,6 +21,7 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Fieldable;
import java.io.Externalizable;
import java.io.IOException;
@@ -148,7 +149,7 @@
Field field;
if (value instanceof TokenStream)
{
- field = new Field(name, (TokenStream)value);
+ field = new Field(name, (TokenStream)value, getTermVectorParameter(flags));
}
else
{
@@ -255,7 +256,7 @@
out.writeBoolean(true);
// boost
out.writeFloat(doc.getBoost());
- List<Field> fields = doc.getFields();
+ List<Fieldable> fields = doc.getFields();
int l = fields.size();
out.writeInt(l);
for (int i = 0; i < l; i++)
@@ -274,7 +275,7 @@
* @param field the Field instance to serialize
* @throws IOException if the Field could not be serialized
*/
- private static void writeField(ObjectOutput out, Field field) throws IOException
+ private static void writeField(ObjectOutput out, Fieldable field) throws IOException
{
// Name
out.writeUTF(field.name());
@@ -295,7 +296,7 @@
* @param field the field from which we extract the value
* @throws IOException if the value could not be serialized
*/
- private static void writeValue(ObjectOutput out, Field field) throws IOException
+ private static void writeValue(ObjectOutput out, Fieldable field) throws IOException
{
Object o = field.stringValue();
if (o != null)
@@ -321,7 +322,7 @@
* @param field the field from which we extract the flags
* @throws IOException if the flags could not be serialized
*/
- private static void writeFlags(ObjectOutput out, Field field) throws IOException
+ private static void writeFlags(ObjectOutput out, Fieldable field) throws IOException
{
int flags = 0;
if (field.isStored())
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-30 11:29:48 UTC (rev 3757)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeIndexer.java 2010-12-30 12:52:09 UTC (rev 3758)
@@ -878,48 +878,15 @@
* @param value the reader value.
* @return a lucene field.
*/
- protected Fieldable createFulltextField(Reader reader)
+ protected Fieldable createFulltextField(Reader value)
{
-
- 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 Field(FieldNames.FULLTEXT, valueString, Field.Store.YES, Field.Index.ANALYZED,
- Field.TermVector.WITH_OFFSETS);
+ return new LazyTextExtractorField(FieldNames.FULLTEXT, value, true, true);
}
else
{
- //return new LazyTextExtractorField(FieldNames.FULLTEXT, value, false, false);
- return new Field(FieldNames.FULLTEXT, valueString, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO);
+ return new LazyTextExtractorField(FieldNames.FULLTEXT, value, false, false);
}
}
13 years, 4 months
exo-jcr SVN: r3757 - in jcr/branches/1.14-IMPR/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/core/query/lucene and 1 other directory.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-12-30 06:29:48 -0500 (Thu, 30 Dec 2010)
New Revision: 3757
Added:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestChangesHolder.java
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: Serializing and Deserializing have been improved
Added: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java (rev 0)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChangesHolder.java 2010-12-30 11:29:48 UTC (rev 3757)
@@ -0,0 +1,377 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * This class is used to serialize and deserialize the changes to apply to the lucene index.
+ *
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class ChangesHolder implements Externalizable
+{
+
+ private static final int STORED_FLAG = 1;
+
+ private static final int COMPRESSED_FLAG = 1 << 1;
+
+ private static final int INDEXED_FLAG = 1 << 2;
+
+ private static final int TOKENIZED_FLAG = 1 << 3;
+
+ private static final int OMIT_NORMS_FLAG = 1 << 4;
+
+ private static final int BINARY_FLAG = 1 << 5;
+
+ private static final int STORE_TERM_VECTOR_FLAG = 1 << 6;
+
+ private static final int STORE_POSITION_WITH_TERM_VECTOR_FLAG = 1 << 7;
+
+ private static final int STORE_OFFSET_WITH_TERM_VECTOR_FLAG = 1 << 8;
+
+ private static final int LAZY_FLAG = 1 << 9;
+
+ private static final int OMIT_TF_FLAG = 1 << 10;
+
+ private static final int BOOST_FLAG = 1 << 11;
+
+ /**
+ * List of doc ids to remove from the index
+ */
+ private List<String> remove;
+
+ /**
+ * Collection of Lucene Documents to add to the index
+ */
+ private Collection<Document> add;
+
+ /**
+ * Default constructor used during the deserializing phase
+ */
+ public ChangesHolder()
+ {
+ }
+
+ /**
+ * @param remove Collection of doc ids to remove from the index
+ * @param add Lucene Documents to add to the index
+ */
+ public ChangesHolder(Collection<String> remove, Collection<Document> add)
+ {
+ this.remove = new ArrayList<String>(remove);
+ this.add = add;
+ }
+
+ /**
+ * @return the collection of doc id to remove
+ */
+ public Collection<String> getRemove()
+ {
+ return remove;
+ }
+
+ /**
+ * @return the collection of lucene document to add
+ */
+ public Collection<Document> getAdd()
+ {
+ return add;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ int length = in.readInt();
+ this.remove = new ArrayList<String>(length);
+ for (int i = 0; i < length; i++)
+ {
+ remove.add(in.readUTF());
+ }
+ this.add = new LinkedList<Document>();
+ while (in.readBoolean())
+ {
+ Document doc = new Document();
+ doc.setBoost(in.readFloat());
+ int l = in.readInt();
+ for (int i = 0; i < l; i++)
+ {
+ doc.add(readField(in, doc));
+ }
+ add.add(doc);
+ }
+ }
+
+ /**
+ * Deserialize the field from the given {@link ObjectInput}
+ * @param in the stream from which we deserialize the Field
+ * @return the deserialized field
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private static Field readField(ObjectInput in, Document doc) throws IOException, ClassNotFoundException
+ {
+ String name = in.readUTF();
+ int flags = in.readInt();
+ float boost = (flags & BOOST_FLAG) > 0 ? in.readFloat() : 1.0f;
+ Object value = in.readObject();
+ Field field;
+ if (value instanceof TokenStream)
+ {
+ field = new Field(name, (TokenStream)value);
+ }
+ else
+ {
+ // The value is a String
+ field = new Field(name, (String)value, getStoreParameter(flags), getIndexParameter(flags), getTermVectorParameter(flags));
+ }
+ field.setBoost(boost);
+ field.setOmitNorms((flags & OMIT_NORMS_FLAG) > 0);
+ field.setOmitTf((flags & OMIT_TF_FLAG) > 0);
+ return field;
+ }
+
+ /**
+ * Returns the index parameter extracted from the flags.
+ *
+ * @param flags the flags of the Lucene field.
+ * @return the index parameter corresponding to the given flags.
+ */
+ private static Field.Index getIndexParameter(int flags)
+ {
+ if ((flags & INDEXED_FLAG) == 0)
+ {
+ return Field.Index.NO;
+ }
+ else if ((flags & TOKENIZED_FLAG) > 0)
+ {
+ return Field.Index.ANALYZED;
+ }
+ else
+ {
+ return Field.Index.NOT_ANALYZED;
+ }
+ }
+
+ /**
+ * Returns the store parameter extracted from the flags.
+ *
+ * @param flags the flags of the Lucene field.
+ * @return the store parameter corresponding to the given flags.
+ */
+ private static Field.Store getStoreParameter(int flags)
+ {
+ if ((flags & COMPRESSED_FLAG) > 0)
+ {
+ return Field.Store.COMPRESS;
+ }
+ else if ((flags & STORED_FLAG) > 0)
+ {
+ return Field.Store.YES;
+ }
+ else
+ {
+ return Field.Store.NO;
+ }
+ }
+
+ /**
+ * Returns the term vector parameter extracted from the flags.
+ *
+ * @param flags the flags of the Lucene field.
+ * @return the term vector parameter corresponding to the given flags.
+ */
+ private static Field.TermVector getTermVectorParameter(int flags)
+ {
+ if (((flags & STORE_POSITION_WITH_TERM_VECTOR_FLAG) > 0)
+ && ((flags & STORE_OFFSET_WITH_TERM_VECTOR_FLAG) > 0))
+ {
+ return Field.TermVector.WITH_POSITIONS_OFFSETS;
+ }
+ else if ((flags & STORE_POSITION_WITH_TERM_VECTOR_FLAG) > 0)
+ {
+ return Field.TermVector.WITH_POSITIONS;
+ }
+ else if ((flags & STORE_OFFSET_WITH_TERM_VECTOR_FLAG) > 0)
+ {
+ return Field.TermVector.WITH_OFFSETS;
+ }
+ else if ((flags & STORE_TERM_VECTOR_FLAG) > 0)
+ {
+ return Field.TermVector.YES;
+ }
+ else
+ {
+ return Field.TermVector.NO;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ int length = remove.size();
+ out.writeInt(length);
+ for (int i = 0; i < length; i++)
+ {
+ out.writeUTF(remove.get(i));
+ }
+ out.flush();
+ for (Document doc : add)
+ {
+ // Indicate that there is a doc to come
+ out.writeBoolean(true);
+ // boost
+ out.writeFloat(doc.getBoost());
+ List<Field> fields = doc.getFields();
+ int l = fields.size();
+ out.writeInt(l);
+ for (int i = 0; i < l; i++)
+ {
+ writeField(out, fields.get(i));
+ }
+ out.flush();
+ }
+ // There is no doc anymore
+ out.writeBoolean(false);
+ }
+
+ /**
+ * Serialize the Field into the given {@link ObjectOutput}
+ * @param out the stream in which we serialize the Field
+ * @param field the Field instance to serialize
+ * @throws IOException if the Field could not be serialized
+ */
+ private static void writeField(ObjectOutput out, Field field) throws IOException
+ {
+ // Name
+ out.writeUTF(field.name());
+ // Flags
+ writeFlags(out, field);
+ if (field.getBoost() != 1.0f)
+ {
+ // Boost
+ out.writeFloat(field.getBoost());
+ }
+ // Value
+ writeValue(out, field);
+ }
+
+ /**
+ * Serialize the value into the given {@link ObjectOutput}
+ * @param out the stream in which we serialize the value
+ * @param field the field from which we extract the value
+ * @throws IOException if the value could not be serialized
+ */
+ private static void writeValue(ObjectOutput out, Field field) throws IOException
+ {
+ Object o = field.stringValue();
+ if (o != null)
+ {
+ // Use writeObject instead of writeUTF because the value could contain unsupported
+ // characters
+ out.writeObject(o);
+ return;
+ }
+ o = field.tokenStreamValue();
+ if (o != null)
+ {
+ out.writeObject(o);
+ return;
+ }
+ o = field.readerValue();
+ throw new RuntimeException("Unsupported value " + o);
+ }
+
+ /**
+ * Serialize the flags into the given {@link ObjectOutput}
+ * @param out the stream in which we serialize the flags
+ * @param field the field from which we extract the flags
+ * @throws IOException if the flags could not be serialized
+ */
+ private static void writeFlags(ObjectOutput out, Field field) throws IOException
+ {
+ int flags = 0;
+ if (field.isStored())
+ {
+ flags |= STORED_FLAG;
+ }
+ if (field.isCompressed())
+ {
+ flags |= COMPRESSED_FLAG;
+ }
+ if (field.isIndexed())
+ {
+ flags |= INDEXED_FLAG;
+ }
+ if (field.isTokenized())
+ {
+ flags |= TOKENIZED_FLAG;
+ }
+ if (field.getOmitNorms())
+ {
+ flags |= OMIT_NORMS_FLAG;
+ }
+ if (field.isBinary())
+ {
+ flags |= BINARY_FLAG;
+ }
+ if (field.isTermVectorStored())
+ {
+ flags |= STORE_TERM_VECTOR_FLAG;
+ }
+ if (field.isStorePositionWithTermVector())
+ {
+ flags |= STORE_POSITION_WITH_TERM_VECTOR_FLAG;
+ }
+ if (field.isStoreOffsetWithTermVector())
+ {
+ flags |= STORE_OFFSET_WITH_TERM_VECTOR_FLAG;
+ }
+ if (field.isLazy())
+ {
+ flags |= LAZY_FLAG;
+ }
+ if (field.getOmitTf())
+ {
+ flags |= OMIT_TF_FLAG;
+ }
+ if (field.getBoost() != 1.0f)
+ {
+ flags |= BOOST_FLAG;
+ }
+ out.writeInt(flags);
+ }
+}
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-30 11:01:59 UTC (rev 3756)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-30 11:29:48 UTC (rev 3757)
@@ -16,8 +16,6 @@
*/
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;
@@ -64,13 +62,9 @@
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;
@@ -91,9 +85,7 @@
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;
@@ -665,9 +657,8 @@
//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);
+ ChangesHolder changes = (ChangesHolder)args[0];
+ index.update(changes.getRemove(), changes.getAdd());
}
return null;
}
@@ -822,12 +813,9 @@
}
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);
+ rpcService.executeCommandOnCoordinator(sendDocs, true, new ChangesHolder(remove, add));
}
catch (SecurityException e)
{
Added: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestChangesHolder.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestChangesHolder.java (rev 0)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestChangesHolder.java 2010-12-30 11:29:48 UTC (rev 3757)
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class TestChangesHolder extends TestCase
+{
+
+ public void testSerNDeserializeDocs() throws Exception
+ {
+ System.out.println("### testSerNDeserializeDocs ###");
+ Collection<Document> add = new ArrayList<Document>(3);
+ Document doc = new Document();
+ doc.setBoost(2.0f);
+ Field fieldFull = new Field("full", "full-value", Store.COMPRESS, Index.ANALYZED_NO_NORMS, TermVector.WITH_POSITIONS_OFFSETS);
+ fieldFull.setBoost(2.0f);
+ fieldFull.setOmitTf(true);
+ doc.add(fieldFull);
+ Field fieldEmpty = new Field("empty", "empty-value", Store.NO, Index.NOT_ANALYZED, TermVector.NO);
+ doc.add(fieldEmpty);
+ add.add(doc);
+ doc = new Document();
+ doc.add(fieldFull);
+ add.add(doc);
+ doc = new Document();
+ doc.add(fieldEmpty);
+ add.add(doc);
+
+ ByteArrayOutputStream baos = null;
+
+ int total = 100000;
+ long start;
+ Collection<String> remove = Collections.emptyList();
+ Collection<Document> addResult = null;
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(new ChangesHolder(remove, add));
+ oos.close();
+ }
+ System.out.println("Custom serialization: total time = " + (System.currentTimeMillis() - start) + ", size = " + baos.size());
+
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ addResult = ((ChangesHolder)ois.readObject()).getAdd();
+ ois.close();
+ }
+ System.out.println("Custom deserialization: total time = " + (System.currentTimeMillis() - start));
+ checkDocs(addResult);
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(add);
+ oos.close();
+ }
+ System.out.println("Native serialization: total time = " + (System.currentTimeMillis() - start) + ", size = " + baos.size());
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ addResult = (Collection<Document>)ois.readObject();
+ ois.close();
+ }
+ System.out.println("Native deserialization: total time = " + (System.currentTimeMillis() - start));
+ checkDocs(addResult);
+ }
+
+ private void checkDocs(Collection<Document> addResult)
+ {
+ assertNotNull(addResult);
+ assertEquals(3, addResult.size());
+ Iterator<Document> it = addResult.iterator();
+ Document doc = it.next();
+ assertEquals(2.0f, doc.getBoost());
+ List<Field> fields = doc.getFields();
+ assertNotNull(fields);
+ assertEquals(2, fields.size());
+ checkFieldFull(fields.get(0));
+ checkFieldEmpty(fields.get(1));
+ doc = it.next();
+ assertEquals(1.0f, doc.getBoost());
+ fields = doc.getFields();
+ assertNotNull(fields);
+ assertEquals(1, fields.size());
+ checkFieldFull(fields.get(0));
+ doc = it.next();
+ assertEquals(1.0f, doc.getBoost());
+ fields = doc.getFields();
+ assertNotNull(fields);
+ assertEquals(1, fields.size());
+ checkFieldEmpty(fields.get(0));
+ }
+
+ private void checkFieldFull(Field field)
+ {
+ assertEquals("full", field.name());
+ assertEquals("full-value", field.stringValue());
+ assertTrue(field.isStored());
+ assertTrue(field.isCompressed());
+ assertTrue(field.isIndexed());
+ assertTrue(field.isTokenized());
+ assertTrue(field.getOmitNorms());
+ assertTrue(field.isTermVectorStored());
+ assertTrue(field.isStoreOffsetWithTermVector());
+ assertTrue(field.isStorePositionWithTermVector());
+ assertTrue(field.getOmitTf());
+ assertFalse(field.isBinary());
+ assertFalse(field.isLazy());
+ assertEquals(2.0f, field.getBoost());
+ assertEquals(0, field.getBinaryLength());
+ assertEquals(0, field.getBinaryOffset());
+ }
+
+ private void checkFieldEmpty(Field field)
+ {
+ assertEquals("empty", field.name());
+ assertEquals("empty-value", field.stringValue());
+ assertFalse(field.isStored());
+ assertFalse(field.isCompressed());
+ assertTrue(field.isIndexed());
+ assertFalse(field.isTokenized());
+ assertFalse(field.getOmitNorms());
+ assertFalse(field.isTermVectorStored());
+ assertFalse(field.isStoreOffsetWithTermVector());
+ assertFalse(field.isStorePositionWithTermVector());
+ assertFalse(field.getOmitTf());
+ assertFalse(field.isBinary());
+ assertFalse(field.isLazy());
+ assertEquals(1.0f, field.getBoost());
+ assertEquals(0, field.getBinaryLength());
+ assertEquals(0, field.getBinaryOffset());
+ }
+
+ public void testSerNDeserializeIds() throws Exception
+ {
+ System.out.println("### testSerNDeserializeIds ###");
+ Collection<String> remove = new ArrayList<String>(3);
+ remove.add(UUID.randomUUID().toString());
+ remove.add(UUID.randomUUID().toString());
+ remove.add(UUID.randomUUID().toString());
+ ByteArrayOutputStream baos = null;
+
+ int total = 100000;
+ long start;
+ Collection<Document> add = Collections.emptyList();
+ Collection<String> addResult = null;
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(new ChangesHolder(remove, add));
+ oos.close();
+ }
+ System.out.println("Custom serialization: total time = " + (System.currentTimeMillis() - start) + ", size = " + baos.size());
+
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ addResult = ((ChangesHolder)ois.readObject()).getRemove();
+ ois.close();
+ }
+ System.out.println("Custom deserialization: total time = " + (System.currentTimeMillis() - start));
+ checkIds(remove, addResult);
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(remove);
+ oos.close();
+ }
+ System.out.println("Native serialization: total time = " + (System.currentTimeMillis() - start) + ", size = " + baos.size());
+ start = System.currentTimeMillis();
+ for (int i = 0; i < total; i++)
+ {
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ addResult = (Collection<String>)ois.readObject();
+ ois.close();
+ }
+ System.out.println("Native deserialization: total time = " + (System.currentTimeMillis() - start));
+ checkIds(remove, addResult);
+ }
+
+ private void checkIds(Collection<String> remove, Collection<String> addResult)
+ {
+ assertNotNull(addResult);
+ assertEquals(remove.size(), addResult.size());
+ Iterator<String> it1 = remove.iterator();
+ Iterator<String> it2 = addResult.iterator();
+ while (it1.hasNext())
+ {
+ assertEquals(it1.next(), it2.next());
+ }
+ }
+}
13 years, 4 months
exo-jcr SVN: r3756 - jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-30 06:01:59 -0500 (Thu, 30 Dec 2010)
New Revision: 3756
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
Log:
EXOJCR-1076: little fix and help changes
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 11:00:19 UTC (rev 3755)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 11:01:59 UTC (rev 3756)
@@ -1,4 +1,7 @@
@echo off
+
+set auth=-b
+
if NOT "%1" == "-u" goto :help
shift
if "%1" == "" goto :help
@@ -15,7 +18,6 @@
shift
)
if "%1" == "-b" (
-set auth=%1
shift
)
set host=%1
@@ -50,10 +52,11 @@
goto :eof
:help
-echo -u ^<user^> -p ^<password^> ^<form_of_authentication^> ^<host:port^> ^<command^>
+echo -u ^<user^> -p ^<password^> [form_of_authentication] ^<host:port^> ^<command^>
echo.
-echo ^<form_of_authentication^> : -b - is used for basic authentication
+echo [form_of_authentication] : -b - is used for basic authentication
echo -f - is used for form authentication
+echo if no authentication set basic authentication is used
echo.
echo ^<command^> : start ^<repo[/ws]^> ^<backup_dir^> [^<incr^>]
echo stop ^<backup_id^>
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 11:00:19 UTC (rev 3755)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 11:01:59 UTC (rev 3756)
@@ -4,11 +4,11 @@
if [ "$1" != "-u" ]
then
-echo " -u <user> -p <password> <form_of_authentication> <host:port> <command> "
+echo " -u <user> -p <password> [form_of_authentication] <host:port> <command> "
echo " "
-echo " <form_of_authentication> : -b - is used for basic authentication "
+echo " [form_of_authentication] : -b - is used for basic authentication "
echo " -f - is used for form authentication "
-echo " "
+echo " if no authentication set basic authentication is used"
echo " <command> : start <repo[/ws]> <backup_dir> [<incr>] "
echo " stop <backup_id> "
echo " status <backup_id> "
13 years, 4 months
exo-jcr SVN: r3755 - jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-30 06:00:19 -0500 (Thu, 30 Dec 2010)
New Revision: 3755
Modified:
jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
Log:
JCR-1499: little fix and help changes
Modified: jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 09:31:54 UTC (rev 3754)
+++ jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 11:00:19 UTC (rev 3755)
@@ -1,4 +1,7 @@
@echo off
+
+set auth=-b
+
if NOT "%1" == "-u" goto :help
shift
if "%1" == "" goto :help
@@ -15,7 +18,6 @@
shift
)
if "%1" == "-b" (
-set auth=%1
shift
)
set host=%1
@@ -50,10 +52,11 @@
goto :eof
:help
-echo -u ^<user^> -p ^<password^> ^<form_of_authentication^> ^<host:port^> ^<command^>
+echo -u ^<user^> -p ^<password^> [form_of_authentication] ^<host:port^> ^<command^>
echo.
-echo ^<form_of_authentication^> : -b - is used for basic authentication
+echo [form_of_authentication] : -b - is used for basic authentication
echo -f - is used for form authentication
+echo if no authentication set basic authentication is used
echo.
echo ^<command^> : start ^<repo[/ws]^> ^<backup_dir^> [^<incr^>]
echo stop ^<backup_id^>
Modified: jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 09:31:54 UTC (rev 3754)
+++ jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 11:00:19 UTC (rev 3755)
@@ -4,11 +4,11 @@
if [ "$1" != "-u" ]
then
-echo " -u <user> -p <password> <form_of_authentication> <host:port> <command> "
+echo " -u <user> -p <password> [form_of_authentication] <host:port> <command> "
echo " "
-echo " <form_of_authentication> : -b - is used for basic authentication "
+echo " [form_of_authentication] : -b - is used for basic authentication "
echo " -f - is used for form authentication "
-echo " "
+echo " if no authentication set basic authentication is used"
echo " <command> : start <repo[/ws]> <backup_dir> [<incr>] "
echo " stop <backup_id> "
echo " status <backup_id> "
13 years, 4 months
exo-jcr SVN: r3754 - in jcr/trunk/applications/exo.jcr.applications.backupconsole.dist: src/main/doc and 1 other directory.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-30 04:31:54 -0500 (Thu, 30 Dec 2010)
New Revision: 3754
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
Log:
EXOJCR-1076: changed scripts due to new requirements
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 09:26:25 UTC (rev 3753)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 09:31:54 UTC (rev 3754)
@@ -1,14 +1,23 @@
@echo off
if NOT "%1" == "-u" goto :help
shift
+if "%1" == "" goto :help
set user=%1
shift
if NOT "%1" == "-p" goto :help
shift
+if "%1" == "" goto :help
set pass=%1
shift
+if "%1" == "" goto :help
+if "%1" == "-f" (
set auth=%1
shift
+)
+if "%1" == "-b" (
+set auth=%1
+shift
+)
set host=%1
shift
@@ -32,7 +41,7 @@
)
if "%auth%" == "-b" (
-jcrbackup http://%user%:%pass%@%host% %comm%
+jcrbackup http://%user%:%pass%@%host%/rest/private %comm%
)
if "%auth%" == "-f" (
jcrbackup http://%host%/portal/rest form POST /portal/login?username=%user%^^^&password=%pass% %comm%
@@ -72,4 +81,4 @@
echo ^<backup_id^> : the identifier for backup
echo ^<incr^> : incremental job period
echo ^<pathToConfigFile^> : path (local) to repository or workspace configuration
-echo force-close-session : close opened sessions on repository or workspace
\ No newline at end of file
+echo force-close-session : close opened sessions on repository or workspace
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 09:26:25 UTC (rev 3753)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 09:31:54 UTC (rev 3754)
@@ -42,15 +42,20 @@
user="$2"
pass="$4"
-host=${6#*"http://"}
+
if [ "$5" = "-f" ]
then
+ host=${6#*"http://"}
newargs="http://$host/portal/rest form POST /portal/login?username=$user&password=$pass ${args[@]:6}"
else
if [ "$5" = "-b" ]
then
- newargs="http://$user:$pass@$host ${args[@]:6}"
+ host=${6#*"http://"}
+ newargs="http://$user:$pass@$host/rest/private ${args[@]:6}"
+ else
+ host=${5#*"http://"}
+ newargs="http://$user:$pass@$host/rest/private ${args[@]:5}"
fi
fi
-./jcrbackup.sh $newargs
\ No newline at end of file
+./jcrbackup.sh $newargs
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2010-12-30 09:26:25 UTC (rev 3753)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2010-12-30 09:31:54 UTC (rev 3754)
@@ -43,10 +43,11 @@
exobackup.sh and exobackup.cmd - suitable for use with GateIn based products like Platform
- -u <user> -p <password> <form_of_authentication> <host:port> <command>
+ -u <user> -p <password> [form_of_authentication] <host:port> <command>
<form_of_authentication> : -b - is used for basic authentication
-f - is used for form authentication
+ if no authentication set basic authentication is used
<command> : start <repo[/ws]> <backup_dir> [<incr>]
stop <backup_id>
13 years, 4 months
exo-jcr SVN: r3753 - in jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist: src/main/doc and 1 other directory.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-30 04:26:25 -0500 (Thu, 30 Dec 2010)
New Revision: 3753
Modified:
jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
Log:
JCR-1499: changes to scripts due to new requirements
Modified: jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 08:37:38 UTC (rev 3752)
+++ jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2010-12-30 09:26:25 UTC (rev 3753)
@@ -1,14 +1,23 @@
@echo off
if NOT "%1" == "-u" goto :help
shift
+if "%1" == "" goto :help
set user=%1
shift
if NOT "%1" == "-p" goto :help
shift
+if "%1" == "" goto :help
set pass=%1
shift
+if "%1" == "" goto :help
+if "%1" == "-f" (
set auth=%1
shift
+)
+if "%1" == "-b" (
+set auth=%1
+shift
+)
set host=%1
shift
@@ -32,7 +41,7 @@
)
if "%auth%" == "-b" (
-jcrbackup http://%user%:%pass%@%host% %comm%
+jcrbackup http://%user%:%pass%@%host%/rest/private %comm%
)
if "%auth%" == "-f" (
jcrbackup http://%host%/portal/rest form POST /portal/login?username=%user%^^^&password=%pass% %comm%
@@ -72,4 +81,4 @@
echo ^<backup_id^> : the identifier for backup
echo ^<incr^> : incremental job period
echo ^<pathToConfigFile^> : path (local) to repository or workspace configuration
-echo force-close-session : close opened sessions on repository or workspace
\ No newline at end of file
+echo force-close-session : close opened sessions on repository or workspace
Modified: jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 08:37:38 UTC (rev 3752)
+++ jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2010-12-30 09:26:25 UTC (rev 3753)
@@ -42,15 +42,20 @@
user="$2"
pass="$4"
-host=${6#*"http://"}
+
if [ "$5" = "-f" ]
then
+ host=${6#*"http://"}
newargs="http://$host/portal/rest form POST /portal/login?username=$user&password=$pass ${args[@]:6}"
else
if [ "$5" = "-b" ]
then
- newargs="http://$user:$pass@$host ${args[@]:6}"
+ host=${6#*"http://"}
+ newargs="http://$user:$pass@$host/rest/private ${args[@]:6}"
+ else
+ host=${5#*"http://"}
+ newargs="http://$user:$pass@$host/rest/private ${args[@]:5}"
fi
fi
-./jcrbackup.sh $newargs
\ No newline at end of file
+./jcrbackup.sh $newargs
Modified: jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
===================================================================
--- jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2010-12-30 08:37:38 UTC (rev 3752)
+++ jcr/branches/1.12.x/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2010-12-30 09:26:25 UTC (rev 3753)
@@ -43,10 +43,11 @@
exobackup.sh and exobackup.cmd - suitable for use with GateIn based products like Platform
- -u <user> -p <password> <form_of_authentication> <host:port> <command>
+ -u <user> -p <password> [form_of_authentication] <host:port> <command>
<form_of_authentication> : -b - is used for basic authentication
-f - is used for form authentication
+ if no authentication set basic authentication is used
<command> : start <repo[/ws]> <backup_dir> [<incr>]
stop <backup_id>
13 years, 4 months
exo-jcr SVN: r3752 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/access and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-30 03:37:38 -0500 (Thu, 30 Dec 2010)
New Revision: 3752
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestPermissions.java
Log:
EXOJCR-1131: Node restore result depends on cache eviction
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java 2010-12-30 08:36:44 UTC (rev 3751)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataRestoreVisitor.java 2010-12-30 08:37:38 UTC (rev 3752)
@@ -18,6 +18,9 @@
*/
package org.exoplatform.services.jcr.impl.core.version;
+import org.exoplatform.services.jcr.access.AccessControlEntry;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
@@ -452,7 +455,10 @@
(PropertyData)dataManager.getItemData(frozen, new QPathEntry(Constants.JCR_FROZENMIXINTYPES, 0),
ItemType.PROPERTY);
+ AccessControlList acl = parentData.getACL();
InternalQName[] mixins = null;
+ String owner = null;
+
if (frozenMixinTypes != null)
{
try
@@ -463,6 +469,29 @@
{
ValueData mvd = mvs.get(i);
mixins[i] = InternalQName.parse(new String(mvd.getAsByteArray()));
+
+ if (mixins[i].equals(Constants.EXO_PRIVILEGEABLE))
+ {
+ PropertyData aclData =
+ (PropertyData)dataManager.getItemData(frozen, new QPathEntry(Constants.EXO_PERMISSIONS, 0),
+ ItemType.PROPERTY);
+
+ acl = new AccessControlList();
+ acl.removePermissions(SystemIdentity.ANY);
+
+ for (ValueData value : aclData.getValues())
+ {
+ acl.addPermissions(new String(value.getAsByteArray(), Constants.DEFAULT_ENCODING));
+ }
+ }
+ else if (mixins[i].equals(Constants.EXO_OWNEABLE))
+ {
+ PropertyData ownerData =
+ (PropertyData)dataManager.getItemData(frozen, new QPathEntry(Constants.EXO_OWNER, 0),
+ ItemType.PROPERTY);
+
+ owner = new String(ownerData.getValues().get(0).getAsByteArray(), Constants.DEFAULT_ENCODING);
+ }
}
}
catch (IllegalNameException e)
@@ -482,6 +511,9 @@
}
}
+ // set new owner if exists
+ acl.setOwner(owner != null ? owner : parentData.getACL().getOwner());
+
InternalQName ptName = null;
try
{
@@ -506,7 +538,7 @@
// create restored version of the node
NodeData restoredData =
new TransientNodeData(nodePath, fidentifier, (existing != null ? existing.getPersistedVersion() : -1), ptName,
- mixins == null ? new InternalQName[0] : mixins, 0, parentData.getIdentifier(), parentData.getACL());
+ mixins == null ? new InternalQName[0] : mixins, 0, parentData.getIdentifier(), acl);
if (updatingPath.contains(nodePath))
{
@@ -729,10 +761,32 @@
}
}
+ boolean isPrivilegeable =
+ nodeTypeDataManager.isNodeType(Constants.EXO_PRIVILEGEABLE, frozen.getPrimaryTypeName(),
+ frozen.getMixinTypeNames());
+
+ boolean isOwneable =
+ nodeTypeDataManager.isNodeType(Constants.EXO_OWNEABLE, frozen.getPrimaryTypeName(),
+ frozen.getMixinTypeNames());
+
+ AccessControlList acl = currentNode().getACL();
+ if (isPrivilegeable || isOwneable)
+ {
+ acl = new AccessControlList();
+ acl.removePermissions(SystemIdentity.ANY);
+
+ for (AccessControlEntry entry : (isPrivilegeable ? frozen.getACL() : currentNode().getACL())
+ .getPermissionEntries())
+ {
+ acl.addPermissions(entry.getIdentity(), new String[]{entry.getPermission()});
+ }
+
+ acl.setOwner(isOwneable ? frozen.getACL().getOwner() : currentNode().getACL().getOwner());
+ }
+
NodeData restoredData =
new TransientNodeData(restoredPath, jcrUuid, frozen.getPersistedVersion(), frozen.getPrimaryTypeName(),
- frozen.getMixinTypeNames(), frozen.getOrderNumber(), currentNode().getIdentifier(), // parent
- frozen.getACL());
+ frozen.getMixinTypeNames(), frozen.getOrderNumber(), currentNode().getIdentifier(), acl);
if (updatingPath.contains(restoredPath))
{
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestPermissions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestPermissions.java 2010-12-30 08:36:44 UTC (rev 3751)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestPermissions.java 2010-12-30 08:37:38 UTC (rev 3752)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.access.PermissionType;
import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
@@ -306,4 +307,258 @@
}
}
}
+
+ /**
+ * Test restore of exo:privilegeable.
+ */
+ public void testPrivilegeable() throws Exception
+ {
+ final String TESTNODE_NAME = "testRestorePrivilegeable";
+ final String CHILD_TESTNODE_NAME1 = "childTestRestorePrivilegeable1";
+ final String CHILD_TESTNODE_NAME2 = "childTestRestorePrivilegeable2";
+ final String CHILD_TESTNODE_NAME3 = "childTestRestorePrivilegeable3";
+ final String CHILD_TESTNODE_NAME4 = "childTestRestorePrivilegeable4";
+
+ Credentials johnCredentials = new CredentialsImpl("john", "exo".toCharArray());
+ SessionImpl johnSession = (SessionImpl)repositoryService.getRepository("db2").login(johnCredentials, "ws1");
+
+ Credentials anonCredentials = new CredentialsImpl(SystemIdentity.ANONIM, "".toCharArray());
+ SessionImpl anonSession = (SessionImpl)repositoryService.getRepository("db2").login(anonCredentials, "ws1");
+
+ NodeImpl node = (NodeImpl)sessionWS1.getRootNode().addNode(TESTNODE_NAME);
+ node.addMixin("exo:privilegeable");
+ node.addMixin("exo:owneable");
+ node.addMixin("mix:versionable");
+ node.setPermission("*:/platform/administrators", PermissionType.ALL);
+ node.setPermission("mary",
+ new String[]{PermissionType.READ, PermissionType.SET_PROPERTY, PermissionType.ADD_NODE});
+ node.removePermission(SystemIdentity.ANY);
+ sessionWS1.save();
+
+ // child node exo:privilegeable & exo:owneable
+ NodeImpl childNode1 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME1);
+ childNode1.addMixin("exo:privilegeable");
+ childNode1.addMixin("exo:owneable");
+ childNode1.setPermission("*:/platform/administrators", PermissionType.ALL);
+ childNode1.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
+ childNode1.removePermission(SystemIdentity.ANY);
+ sessionWS1.save();
+
+ // child node all inherited from parent
+ NodeImpl childNode2 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME2);
+ sessionWS1.save();
+
+ // child node exo:owneable
+ node = (NodeImpl)johnSession.getRootNode().getNode(TESTNODE_NAME);
+ NodeImpl childNode3 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME3);
+ childNode3.addMixin("exo:owneable");
+ johnSession.save();
+
+ node = (NodeImpl)sessionWS1.getRootNode().getNode(TESTNODE_NAME);
+
+ // child node exo:privilegeable
+ NodeImpl childNode4 = (NodeImpl)node.addNode(CHILD_TESTNODE_NAME4);
+ childNode4.addMixin("exo:privilegeable");
+ childNode4.setPermission("*:/platform/administrators", PermissionType.ALL);
+ childNode4.setPermission("mary", new String[]{PermissionType.READ, PermissionType.SET_PROPERTY});
+ childNode4.removePermission(SystemIdentity.ANY);
+ sessionWS1.save();
+
+ // check what we have
+ NodeImpl marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), "admin");
+
+ NodeImpl marysChildNode1 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME1);
+ assertTrue(marysChildNode1.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode1.hasPermission(PermissionType.SET_PROPERTY));
+ assertFalse(marysChildNode1.hasPermission(PermissionType.ADD_NODE));
+ assertEquals(((NodeData)marysChildNode1.getData()).getACL().getOwner(), "admin");
+
+ NodeImpl marysChildNode2 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME2);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));;
+ assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
+
+ NodeImpl marysChildNode3 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME3);
+ assertTrue(marysChildNode3.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode3.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysChildNode3.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysChildNode3.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysChildNode3.getData()).getACL().getOwner(), "john");
+
+ NodeImpl marysChildNode4 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME4);
+ assertTrue(marysChildNode4.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode4.hasPermission(PermissionType.SET_PROPERTY));
+ assertFalse(marysChildNode4.hasPermission(PermissionType.REMOVE));;
+ assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
+
+ // for __anonim
+ try
+ {
+ anonSession.getRootNode().getNode(TESTNODE_NAME);
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+
+ // v1
+ node.checkin();
+ node.checkout();
+
+ try
+ {
+ // restore v1
+ node.restore("1", true);
+ }
+ catch (AccessDeniedException e)
+ {
+ fail("Restore should succeed");
+ }
+
+ // check what we have after restore
+ marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), "admin");
+
+ marysChildNode1 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME1);
+ assertTrue(marysChildNode1.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode1.hasPermission(PermissionType.SET_PROPERTY));
+ assertFalse(marysChildNode1.hasPermission(PermissionType.ADD_NODE));
+ assertEquals(((NodeData)marysChildNode1.getData()).getACL().getOwner(), "admin");
+
+ marysChildNode2 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME2);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");;
+
+ marysChildNode3 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME3);
+ assertTrue(marysChildNode3.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode3.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysChildNode3.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysChildNode3.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysChildNode3.getData()).getACL().getOwner(), "john");
+
+ marysChildNode4 = (NodeImpl)marysNode.getNode(CHILD_TESTNODE_NAME4);
+ assertTrue(marysChildNode4.hasPermission(PermissionType.READ));
+ assertTrue(marysChildNode4.hasPermission(PermissionType.SET_PROPERTY));
+ assertFalse(marysChildNode4.hasPermission(PermissionType.REMOVE));;
+ assertEquals(((NodeData)marysChildNode2.getData()).getACL().getOwner(), "admin");
+
+ // for __anonim
+ try
+ {
+ anonSession.getRootNode().getNode(TESTNODE_NAME);
+ }
+ catch (AccessDeniedException e)
+ {
+ // ok
+ }
+ finally
+ {
+ anonSession.logout();
+ }
+
+ johnSession.logout();
+ }
+
+ /**
+ * Test restore of exo:privilegeable.
+ */
+ public void testPrivilegeable2() throws Exception
+ {
+ final String TESTNODE_NAME = "testRestorePrivilegeable2";
+
+ NodeImpl node = (NodeImpl)sessionWS1.getRootNode().addNode(TESTNODE_NAME);
+ node.addMixin("exo:privilegeable");
+ node.addMixin("mix:versionable");
+ node.setPermission("*:/platform/administrators", PermissionType.ALL);
+ node.setPermission("mary",
+ new String[]{PermissionType.READ, PermissionType.SET_PROPERTY, PermissionType.ADD_NODE});
+ node.removePermission(SystemIdentity.ANY);
+ sessionWS1.save();
+
+ // check what we have
+ NodeImpl marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), SystemIdentity.SYSTEM);
+
+ // v1
+ node.checkin();
+ node.checkout();
+
+ try
+ {
+ // restore v1
+ node.restore("1", true);
+ }
+ catch (AccessDeniedException e)
+ {
+ fail("Restore should succeed");
+ }
+
+ // check what we have after restore
+ marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertTrue(marysNode.hasPermission(PermissionType.READ));
+ assertTrue(marysNode.hasPermission(PermissionType.SET_PROPERTY));
+ assertTrue(marysNode.hasPermission(PermissionType.ADD_NODE));
+ assertFalse(marysNode.hasPermission(PermissionType.REMOVE));
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), SystemIdentity.SYSTEM);
+ }
+
+ /**
+ * Test restore of exo:privilegeable.
+ */
+ public void testPrivilegeable3() throws Exception
+ {
+ final String TESTNODE_NAME = "testRestorePrivilegeable3";
+
+ NodeImpl node = (NodeImpl)sessionWS1.getRootNode().addNode(TESTNODE_NAME);
+ node.addMixin("exo:owneable");
+ node.addMixin("mix:versionable");
+ sessionWS1.save();
+
+ // check what we have
+ NodeImpl marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertEquals(marysNode.getACL().getPermissionsSize(), 4);
+ assertEquals(marysNode.getACL().getPermissions(SystemIdentity.ANY).size(), 4);
+ assertEquals(marysNode.getACL().getPermissions("mary").size(), 0);
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), "admin");
+
+ // v1
+ node.checkin();
+ node.checkout();
+
+ try
+ {
+ // restore v1
+ node.restore("1", true);
+ }
+ catch (AccessDeniedException e)
+ {
+ fail("Restore should succeed");
+ }
+
+ // check what we have after restore
+ marysNode = (NodeImpl)sessionMaryWS1.getRootNode().getNode(TESTNODE_NAME);
+ assertEquals(marysNode.getACL().getPermissionsSize(), 4);
+ assertEquals(marysNode.getACL().getPermissions(SystemIdentity.ANY).size(), 4);
+ assertEquals(marysNode.getACL().getPermissions("mary").size(), 0);
+ assertEquals(((NodeData)marysNode.getData()).getACL().getOwner(), "admin");
+ }
+
}
13 years, 4 months