exo-jcr SVN: r2636 - kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 10:18:23 -0400 (Wed, 16 Jun 2010)
New Revision: 2636
Modified:
kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java
Log:
EXOJCR-756: set "Id" property
Modified: kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java
===================================================================
--- kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java 2010-06-16 14:17:44 UTC (rev 2635)
+++ kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java 2010-06-16 14:18:23 UTC (rev 2636)
@@ -22,7 +22,7 @@
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: TesterSecurityManager.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*
*/
public class TestSecurityManager extends SecurityManager
Property changes on: kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years
exo-jcr SVN: r2635 - in kernel/trunk: exo.kernel.commons.test and 6 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 10:17:44 -0400 (Wed, 16 Jun 2010)
New Revision: 2635
Added:
kernel/trunk/exo.kernel.commons.test/
kernel/trunk/exo.kernel.commons.test/pom.xml
kernel/trunk/exo.kernel.commons.test/src/
kernel/trunk/exo.kernel.commons.test/src/main/
kernel/trunk/exo.kernel.commons.test/src/main/java/
kernel/trunk/exo.kernel.commons.test/src/main/java/org/
kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/
kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/
kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java
Log:
EXOJCR-756: move TestSecuritManager ot kernel project
Added: kernel/trunk/exo.kernel.commons.test/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.commons.test/pom.xml (rev 0)
+++ kernel/trunk/exo.kernel.commons.test/pom.xml 2010-06-16 14:17:44 UTC (rev 2635)
@@ -0,0 +1,37 @@
+
+ <!--
+
+ Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version. This software is distributed in the hope that it will be
+ useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU
+ Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>kernel-parent</artifactId>
+ <version>2.3.0-Beta01-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>exo.kernel.commons.test</artifactId>
+
+ <name>eXo Kernel :: Commons :: Test Util</name>
+ <description>eXo Commons Test Util</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java
===================================================================
--- kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java (rev 0)
+++ kernel/trunk/exo.kernel.commons.test/src/main/java/org/exoplatform/commons/TestSecurityManager.java 2010-06-16 14:17:44 UTC (rev 2635)
@@ -0,0 +1,105 @@
+/*
+ * 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.commons;
+
+import java.security.Permission;
+
+/**
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: TesterSecurityManager.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class TestSecurityManager extends SecurityManager
+{
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void checkPermission(Permission perm)
+ {
+ try
+ {
+ super.checkPermission(perm);
+ }
+ catch (SecurityException se)
+ {
+ Throwable e = se;
+
+ boolean srcCode = false;
+ boolean testCode = false;
+
+ while (e != null)
+ {
+ StackTraceElement[] traceElements = e.getStackTrace();
+ for (int i = 0; i < traceElements.length; i++)
+ {
+ String className = traceElements[i].getClassName();
+ String fileName = traceElements[i].getFileName();
+
+ if (className.startsWith("org.exoplatform"))
+ {
+ // hide Exception during JCR initialization
+ if (fileName.equals("BaseStandaloneTest.java"))
+ {
+ return;
+ }
+
+ if (fileName.startsWith("Test") || fileName.endsWith("Test.java")
+ || fileName.endsWith("TestBase.java") || fileName.equals("Probe.java")
+ || fileName.equals("ExportBase.java"))
+ {
+ testCode = true;
+ }
+ else
+ {
+ srcCode = true;
+ }
+ }
+ else if (className.startsWith("org.apache.jackrabbit.test"))
+ {
+ // Allow access to instances
+ if (fileName.equals("RepositoryHelper.java"))
+ {
+ return;
+ }
+
+ if (fileName.endsWith("Test.java") || fileName.equals("JCRTestResult.java"))
+ {
+ testCode = true;
+ }
+ }
+ else if (className.startsWith("org.slf4j.impl.Log4jLoggerFactory"))
+ {
+ return;
+ }
+ }
+
+ e = e.getCause();
+ }
+
+ // hide Exception if only test code exists
+ if (!srcCode && testCode)
+ {
+ return;
+ }
+
+ throw se;
+ }
+ }
+}
14 years
exo-jcr SVN: r2634 - core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-06-16 09:31:29 -0400 (Wed, 16 Jun 2010)
New Revision: 2634
Modified:
core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java
Log:
EXOJCR-756: PDFDocumentReader.getContentAsText wrapped into doPrivileged
Modified: core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java
===================================================================
--- core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java 2010-06-16 13:20:35 UTC (rev 2633)
+++ core/trunk/exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/PDFDocumentReader.java 2010-06-16 13:31:29 UTC (rev 2634)
@@ -21,13 +21,13 @@
import com.lowagie.text.pdf.PdfDate;
import com.lowagie.text.pdf.PdfReader;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.util.PDFTextStripper;
import org.exoplatform.commons.utils.ISO8601;
import org.exoplatform.services.document.DCMetaData;
import org.exoplatform.services.document.DocumentReadException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.util.PDFTextStripper;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -37,6 +37,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.text.ParseException;
import java.util.Calendar;
import java.util.HashMap;
@@ -74,53 +77,81 @@
* @param is an input stream with .pdf file content.
* @return The string only with text from file content.
*/
- public String getContentAsText(InputStream is) throws IOException, DocumentReadException
+ public String getContentAsText(final InputStream is) throws IOException, DocumentReadException
{
- if (is == null)
+
+ try
{
- throw new NullPointerException("InputStream is null.");
+ return (String)AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ if (is == null)
+ {
+ throw new NullPointerException("InputStream is null.");
+ }
+ PDDocument pdDocument = null;
+ StringWriter sw = new StringWriter();
+ try
+ {
+ if (is.available() == 0)
+ return "";
+
+ try
+ {
+ pdDocument = PDDocument.load(is);
+ }
+ catch (IOException e)
+ {
+ throw new DocumentReadException("Can not load PDF document.", e);
+ }
+
+ PDFTextStripper stripper = new PDFTextStripper();
+ stripper.setStartPage(1);
+ stripper.setEndPage(Integer.MAX_VALUE);
+ stripper.writeText(pdDocument, sw);
+ }
+ finally
+ {
+ if (pdDocument != null)
+ try
+ {
+ pdDocument.close();
+ }
+ catch (IOException e)
+ {
+ }
+ if (is != null)
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+ return sw.toString();
+ }
+ });
+
}
- PDDocument pdDocument = null;
- StringWriter sw = new StringWriter();
- try
+ catch (PrivilegedActionException pae)
{
- if (is.available() == 0)
- return "";
-
- try
+ Throwable cause = pae.getCause();
+ if (cause instanceof IOException)
{
- pdDocument = PDDocument.load(is);
+ throw (IOException)cause;
}
- catch (IOException e)
+ else if (cause instanceof RuntimeException)
{
- throw new DocumentReadException("Can not load PDF document.", e);
+ throw (RuntimeException)cause;
}
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
- PDFTextStripper stripper = new PDFTextStripper();
- stripper.setStartPage(1);
- stripper.setEndPage(Integer.MAX_VALUE);
- stripper.writeText(pdDocument, sw);
- }
- finally
- {
- if (pdDocument != null)
- try
- {
- pdDocument.close();
- }
- catch (IOException e)
- {
- }
- if (is != null)
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- }
- }
- return sw.toString();
}
public String getContentAsText(InputStream is, String encoding) throws IOException, DocumentReadException
14 years
exo-jcr SVN: r2633 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-06-16 09:20:35 -0400 (Wed, 16 Jun 2010)
New Revision: 2633
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-758: indexer updated
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-06-16 12:54:31 UTC (rev 2632)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-06-16 13:20:35 UTC (rev 2633)
@@ -16,8 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import java.io.IOException;
-
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -26,116 +24,128 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.query.lucene.constraint.EvaluationContext;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+
/**
* <code>JackrabbitIndexSearcher</code> implements an index searcher with
* jackrabbit specific optimizations.
*/
-public class JcrIndexSearcher
- extends IndexSearcher
- implements EvaluationContext {
+public class JcrIndexSearcher extends IndexSearcher implements EvaluationContext
+{
- /**
- * The session that executes the query.
- */
- private final SessionImpl session;
+ /**
+ * The session that executes the query.
+ */
+ private final SessionImpl session;
- /**
- * The underlying index reader.
- */
- private final IndexReader reader;
+ /**
+ * The underlying index reader.
+ */
+ private final IndexReader reader;
- /**
- * The item state manager of the workspace.
- */
- private final ItemDataConsumer ism;
+ /**
+ * The item state manager of the workspace.
+ */
+ private final ItemDataConsumer ism;
- /**
- * Creates a new jackrabbit index searcher.
- *
- * @param s the session that executes the query.
- * @param r the index reader.
- * @param ism the shared item state manager.
- */
- public JcrIndexSearcher(SessionImpl s,
- IndexReader r,
- ItemDataConsumer ism) {
- super(r);
- this.session = s;
- this.reader = r;
- this.ism = ism;
- }
+ /**
+ * Creates a new jackrabbit index searcher.
+ *
+ * @param s the session that executes the query.
+ * @param r the index reader.
+ * @param ism the shared item state manager.
+ */
+ public JcrIndexSearcher(SessionImpl s, IndexReader r, ItemDataConsumer ism)
+ {
+ super(r);
+ this.session = s;
+ this.reader = r;
+ this.ism = ism;
+ }
- /**
- * Executes the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @param sort the sort criteria.
- * @param resultFetchHint a hint on how many results should be fetched.
- * @param selectorName the single selector name for the query hits.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public MultiColumnQueryHits execute(Query query,
- Sort sort,
- long resultFetchHint,
- InternalQName selectorName)
- throws IOException {
- return new QueryHitsAdapter(
- evaluate(query, sort, resultFetchHint), selectorName);
- }
+ /**
+ * Executes the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @param sort the sort criteria.
+ * @param resultFetchHint a hint on how many results should be fetched.
+ * @param selectorName the single selector name for the query hits.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public MultiColumnQueryHits execute(Query query, Sort sort, long resultFetchHint, InternalQName selectorName)
+ throws IOException
+ {
+ return new QueryHitsAdapter(evaluate(query, sort, resultFetchHint), selectorName);
+ }
- /**
- * Evaluates the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @param sort the sort criteria.
- * @param resultFetchHint a hint on how many results should be fetched.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public QueryHits evaluate(Query query, Sort sort, long resultFetchHint)
- throws IOException {
- query = query.rewrite(reader);
- QueryHits hits = null;
- if (query instanceof JcrQuery) {
- hits = ((JcrQuery) query).execute(this, session, sort);
- }
- if (hits == null) {
- if (sort == null) {
- hits = new LuceneQueryHits(reader, this, query);
- } else {
- hits = new SortedLuceneQueryHits(
- reader, this, query, sort, resultFetchHint);
+ /**
+ * Evaluates the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @param sort the sort criteria.
+ * @param resultFetchHint a hint on how many results should be fetched.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public QueryHits evaluate(final Query query, final Sort sort, final long resultFetchHint) throws IOException
+ {
+ return SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<QueryHits>()
+ {
+ public QueryHits run() throws Exception
+ {
+ Query localQuery = query.rewrite(reader);
+ QueryHits hits = null;
+ if (localQuery instanceof JcrQuery)
+ {
+ hits = ((JcrQuery)localQuery).execute(JcrIndexSearcher.this, session, sort);
}
- }
- return hits;
- }
+ if (hits == null)
+ {
+ if (sort == null)
+ {
+ hits = new LuceneQueryHits(reader, JcrIndexSearcher.this, localQuery);
+ }
+ else
+ {
+ hits = new SortedLuceneQueryHits(reader, JcrIndexSearcher.this, localQuery, sort, resultFetchHint);
+ }
+ }
+ return hits;
+ }
+ });
+ }
- //------------------------< EvaluationContext >-----------------------------
+ //------------------------< EvaluationContext >-----------------------------
- /**
- * Evaluates the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public QueryHits evaluate(Query query) throws IOException {
- return evaluate(query, new Sort(), Integer.MAX_VALUE);
- }
+ /**
+ * Evaluates the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public QueryHits evaluate(Query query) throws IOException
+ {
+ return evaluate(query, new Sort(), Integer.MAX_VALUE);
+ }
- /**
- * @return session that executes the query.
- */
- public SessionImpl getSession() {
- return session;
- }
+ /**
+ * @return session that executes the query.
+ */
+ public SessionImpl getSession()
+ {
+ return session;
+ }
- /**
- * @return the item state manager of the workspace.
- */
- public ItemDataConsumer getItemStateManager() {
- return ism;
- }
+ /**
+ * @return the item state manager of the workspace.
+ */
+ public ItemDataConsumer getItemStateManager()
+ {
+ return ism;
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-16 12:54:31 UTC (rev 2632)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-16 13:20:35 UTC (rev 2633)
@@ -1426,39 +1426,45 @@
{
// File config = PrivilegedFileHelper.file(indexingConfigPath);
-
- InputStream is = SearchIndex.class.getResourceAsStream(indexingConfigPath);
- if (is == null)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- try
+ public Object run()
{
- is = cfm.getInputStream(indexingConfigPath);
+ InputStream is = SearchIndex.class.getResourceAsStream(indexingConfigPath);
+ if (is == null)
+ {
+ try
+ {
+ is = cfm.getInputStream(indexingConfigPath);
+ }
+ catch (Exception e1)
+ {
+ log.warn("Unable to load configuration " + indexingConfigPath);
+ }
+ }
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new IndexingConfigurationEntityResolver());
+ indexingConfiguration = builder.parse(is).getDocumentElement();
+ }
+ catch (ParserConfigurationException e)
+ {
+ log.warn("Unable to create XML parser", e);
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception parsing " + indexingConfigPath, e);
+ }
+ catch (SAXException e)
+ {
+ log.warn("Exception parsing " + indexingConfigPath, e);
+ }
+ return null;
}
- catch (Exception e1)
- {
- log.warn("Unable to load configuration " + indexingConfigPath);
- }
- }
-
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver(new IndexingConfigurationEntityResolver());
- indexingConfiguration = builder.parse(is).getDocumentElement();
- }
- catch (ParserConfigurationException e)
- {
- log.warn("Unable to create XML parser", e);
- }
- catch (IOException e)
- {
- log.warn("Exception parsing " + indexingConfigPath, e);
- }
- catch (SAXException e)
- {
- log.warn("Exception parsing " + indexingConfigPath, e);
- }
+ });
}
}
return indexingConfiguration;
@@ -1662,10 +1668,9 @@
* aggregate roots are collected in this map. Key=UUID,
* value=NodeState.
*/
- protected void retrieveAggregateRoot(Set<String> removedNodeIds, Map<String, NodeData> map)
+ protected void retrieveAggregateRoot(final Set<String> removedNodeIds, final Map<String, NodeData> map)
{
-
if (indexingConfig != null)
{
AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
@@ -1673,55 +1678,62 @@
{
return;
}
- int found = 0;
long time = System.currentTimeMillis();
- try
+ int found = SecurityHelper.doPriviledgedAction(new PrivilegedAction<Integer>()
{
- CachingMultiIndexReader reader = index.getIndexReader();
- try
+ public Integer run()
{
- Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
- TermDocs tDocs = reader.termDocs();
+ int found = 0;
try
{
- ItemDataConsumer ism = getContext().getItemStateManager();
- for (Iterator<String> it = removedNodeIds.iterator(); it.hasNext();)
+ CachingMultiIndexReader reader = index.getIndexReader();
+ try
{
- String id = it.next();
- aggregateUUIDs = aggregateUUIDs.createTerm(id);
- tDocs.seek(aggregateUUIDs);
- while (tDocs.next())
+ Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID, "");
+ TermDocs tDocs = reader.termDocs();
+ try
{
- Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
- String uuid = doc.get(FieldNames.UUID);
- ItemData itd = ism.getItemData(uuid);
- if (itd == null)
+ ItemDataConsumer ism = getContext().getItemStateManager();
+ for (Iterator<String> it = removedNodeIds.iterator(); it.hasNext();)
{
- continue;
+ String id = it.next();
+ aggregateUUIDs = aggregateUUIDs.createTerm(id);
+ tDocs.seek(aggregateUUIDs);
+ while (tDocs.next())
+ {
+ Document doc = reader.document(tDocs.doc(), FieldSelectors.UUID);
+ String uuid = doc.get(FieldNames.UUID);
+ ItemData itd = ism.getItemData(uuid);
+ if (itd == null)
+ {
+ continue;
+ }
+ if (!itd.isNode())
+ {
+ throw new RepositoryException("Item with id:" + uuid + " is not a node");
+ }
+ map.put(uuid, (NodeData)itd);
+ found++;
+ }
}
- if (!itd.isNode())
- {
- throw new RepositoryException("Item with id:" + uuid + " is not a node");
- }
- map.put(uuid, (NodeData)itd);
- found++;
}
+ finally
+ {
+ tDocs.close();
+ }
}
+ finally
+ {
+ reader.release();
+ }
}
- finally
+ catch (Exception e)
{
- tDocs.close();
+ log.warn("Exception while retrieving aggregate roots", e);
}
+ return found;
}
- finally
- {
- reader.release();
- }
- }
- catch (Exception e)
- {
- log.warn("Exception while retrieving aggregate roots", e);
- }
+ });
time = System.currentTimeMillis() - time;
log.debug("Retrieved {} aggregate roots in {} ms.", new Integer(found), new Long(time));
}
14 years
exo-jcr SVN: r2632 - in kernel/trunk/exo.kernel.container/src: test/java/org/exoplatform/container/configuration and 1 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-06-16 08:54:31 -0400 (Wed, 16 Jun 2010)
New Revision: 2632
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestComponentPlugin.java
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/test-component-plugin-configuration.xml
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
Log:
EXOJCR-786: The method that registers plugins should be overloadable.
Now we can use the same method name to register different plugin types, the kernel will use the method that matches the best with the type of the plugin
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-06-16 12:49:06 UTC (rev 2631)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java 2010-06-16 12:54:31 UTC (rev 2632)
@@ -137,13 +137,19 @@
try
{
- Class clazz = Class.forName(plugin.getType());
- ComponentPlugin cplugin = (ComponentPlugin)container.createComponent(clazz, plugin.getInitParams());
+ Class pluginClass = Class.forName(plugin.getType());
+ ComponentPlugin cplugin = (ComponentPlugin)container.createComponent(pluginClass, plugin.getInitParams());
cplugin.setName(plugin.getName());
cplugin.setDescription(plugin.getDescription());
- clazz = component.getClass();
+ Class clazz = component.getClass();
- Method m = getSetMethod(clazz, plugin.getSetMethod());
+ Method m = getSetMethod(clazz, plugin.getSetMethod(), pluginClass);
+ if (m == null)
+ {
+ log.error("Cannot find the method '" + plugin.getSetMethod() + "' that has only one parameter of type '"
+ + pluginClass.getName() + "' in the class '" + clazz.getName() + "'.");
+ continue;
+ }
Object[] params = {cplugin};
m.invoke(component, params);
if (debug)
@@ -160,9 +166,18 @@
}
}
- private Method getSetMethod(Class clazz, String name)
+ /**
+ * Finds the best "set method" according to the given method name and type of plugin
+ * @param clazz the {@link Class} of the target component
+ * @param name the name of the method
+ * @param pluginClass the {@link Class} of the plugin
+ * @return the "set method" corresponding to the given context
+ */
+ private Method getSetMethod(Class clazz, String name, Class pluginClass)
{
Method[] methods = clazz.getMethods();
+ Method bestCandidate = null;
+ int depth = -1;
for (Method m : methods)
{
if (name.equals(m.getName()))
@@ -170,13 +185,51 @@
Class[] types = m.getParameterTypes();
if (types != null && types.length == 1 && ComponentPlugin.class.isAssignableFrom(types[0]))
{
- return m;
+ int currentDepth = getClosestMatchDepth(pluginClass, types[0]);
+ if (currentDepth == 0)
+ {
+ return m;
+ }
+ else if (depth == -1 || depth > currentDepth)
+ {
+ bestCandidate = m;
+ depth = currentDepth;
+ }
}
}
}
- return null;
+ return bestCandidate;
}
+ /**
+ * Check if the given plugin class is assignable from the given type, if not we recheck with its parent class
+ * until we find the closest match.
+ * @param pluginClass the class of the plugin
+ * @param type the class from which the plugin must be assignable
+ * @return The total amount of times we had to up the hierarchy of the plugin
+ */
+ private static int getClosestMatchDepth(Class pluginClass, Class type)
+ {
+ return getClosestMatchDepth(pluginClass, type, 0);
+ }
+
+ /**
+ * Check if the given plugin class is assignable from the given type, if not we recheck with its parent class
+ * until we find the closest match.
+ * @param pluginClass the class of the plugin
+ * @param type the class from which the plugin must be assignable
+ * @param depth the current amount of times that we had to up the hierarchy of the plugin
+ * @return The total amount of times we had to up the hierarchy of the plugin
+ */
+ private static int getClosestMatchDepth(Class pluginClass, Class type, int depth)
+ {
+ if (pluginClass == null || pluginClass.isAssignableFrom(type))
+ {
+ return depth;
+ }
+ return getClosestMatchDepth(pluginClass.getSuperclass(), type, depth + 1);
+ }
+
public void verify(PicoContainer container)
{
}
Added: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestComponentPlugin.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestComponentPlugin.java (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestComponentPlugin.java 2010-06-16 12:54:31 UTC (rev 2632)
@@ -0,0 +1,122 @@
+/*
+ * 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.container.configuration;
+
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.container.component.ComponentPlugin;
+import org.exoplatform.container.jmx.AbstractTestContainer;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestComponentPlugin extends AbstractTestContainer
+{
+ public void testComponentPluginOverloading()
+ {
+ RootContainer rootContainer = createRootContainer("test-component-plugin-configuration.xml");
+ A a = (A)rootContainer.getComponentInstanceOfType(A.class);
+ assertNotNull(a);
+ assertEquals(1, a.countRegisterCP);
+ assertEquals(1, a.countRegisterACP);
+ assertEquals(2, a.countRegisterCP1);
+ }
+
+ public static class A
+ {
+ public int countRegisterCP;
+
+ public int countRegisterACP;
+
+ public int countRegisterCP1;
+
+ public void register(ComponentPlugin plugin)
+ {
+ countRegisterCP++;
+ }
+
+ public void register(AComponentPlugin plugin)
+ {
+ countRegisterACP++;
+ }
+
+ public void register(ComponentPlugin1 plugin)
+ {
+ countRegisterCP1++;
+ }
+
+ }
+
+ public static abstract class AComponentPlugin implements ComponentPlugin
+ {
+
+ public String getDescription()
+ {
+ return null;
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public void setDescription(String s)
+ {
+ }
+
+ public void setName(String s)
+ {
+ }
+ }
+
+ public static class ComponentPlugin1 extends AComponentPlugin
+ {
+ }
+
+ public static class ComponentPlugin2 extends AComponentPlugin
+ {
+ }
+
+ public static class ComponentPlugin3 extends ComponentPlugin1
+ {
+ }
+
+ public static class ComponentPlugin4 implements ComponentPlugin
+ {
+
+ public String getDescription()
+ {
+ return null;
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public void setDescription(String s)
+ {
+ }
+
+ public void setName(String s)
+ {
+ }
+ }
+}
Added: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/test-component-plugin-configuration.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/test-component-plugin-configuration.xml (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/test-component-plugin-configuration.xml 2010-06-16 12:54:31 UTC (rev 2632)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<configuration
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <component>
+ <type>org.exoplatform.container.configuration.TestComponentPlugin$A</type>
+ <component-plugins>
+ <component-plugin>
+ <name>Plugin1</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.container.configuration.TestComponentPlugin$ComponentPlugin1</type>
+ </component-plugin>
+ <component-plugin>
+ <name>Plugin2</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.container.configuration.TestComponentPlugin$ComponentPlugin2</type>
+ </component-plugin>
+ <component-plugin>
+ <name>Plugin3</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.container.configuration.TestComponentPlugin$ComponentPlugin3</type>
+ </component-plugin>
+ <component-plugin>
+ <name>Plugin4</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.container.configuration.TestComponentPlugin$ComponentPlugin4</type>
+ </component-plugin>
+ </component-plugins>
+ </component>
+
+</configuration>
\ No newline at end of file
14 years
exo-jcr SVN: r2631 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 08:49:06 -0400 (Wed, 16 Jun 2010)
New Revision: 2631
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
Log:
EXOJCR-756: set "Id" property
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-16 12:41:58 UTC (rev 2630)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-16 12:49:06 UTC (rev 2631)
@@ -22,7 +22,7 @@
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: TesterSecurityManager.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class TesterSecurityManager extends SecurityManager
{
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years
exo-jcr SVN: r2630 - jcr/trunk/exo.jcr.component.core/src/test/resources.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 08:41:58 -0400 (Wed, 16 Jun 2010)
New Revision: 2630
Modified:
jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
Log:
EXOJCR-756: remove unused permission
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-16 10:10:30 UTC (rev 2629)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/test.policy 2010-06-16 12:41:58 UTC (rev 2630)
@@ -7,7 +7,6 @@
};
grant codeBase "@TEST_CLASSES@-"{
- permission java.lang.RuntimePermission "setSecurityManager";
permission java.lang.RuntimePermission "getJCRSystemSession";
permission java.lang.RuntimePermission "manageRepository";
};
14 years
exo-jcr SVN: r2629 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/utils/io and 1 other directory.
by do-not-reply@jboss.org
Author: natasha.vakulenko
Date: 2010-06-16 06:10:30 -0400 (Wed, 16 Jun 2010)
New Revision: 2629
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SwapFile.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
Log:
EXOJCR-791: Added new tests testDeleteExistingSwapFile (in class TestSwapFile), testDeleteExistingFile and testDeleteAquireFile(in class TestSpoolFile). In the classes SpoolFile and SwapFile in methods delete() were changed to inform the correct about delete non-existing files,
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java 2010-06-16 09:50:33 UTC (rev 2628)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SpoolFile.java 2010-06-16 10:10:30 UTC (rev 2629)
@@ -109,14 +109,17 @@
users.clear();
users = null;
+ final SpoolFile sf = this;
+
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
{
public Boolean run()
{
- return SpoolFile.super.delete();
+ return sf.exists() ? SpoolFile.super.delete() : true;
}
};
return AccessController.doPrivileged(action);
+
}
return false;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SwapFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SwapFile.java 2010-06-16 09:50:33 UTC (rev 2628)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/SwapFile.java 2010-06-16 10:10:30 UTC (rev 2629)
@@ -157,12 +157,13 @@
{
synchronized (inShare)
{
+ final SpoolFile sf = this;
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
{
public Boolean run()
{
- return SwapFile.super.delete();
+ return sf.exists() ? SwapFile.super.delete() : true;
}
};
boolean res = AccessController.doPrivileged(action);
@@ -170,13 +171,14 @@
if (res)
{
// remove from shared files list
- inShare.remove(getAbsolutePath());
+ inShare.remove(PrivilegedFileHelper.getAbsolutePath(this));
// make sure that the file doesn't make any other thread await in 'get' method
// impossible case as 'delete' and 'get' which may waiting for, synchronized by inShare map.
// spoolDone();
return true;
+
}
return false;
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java 2010-06-16 09:50:33 UTC (rev 2628)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSpoolFile.java 2010-06-16 10:10:30 UTC (rev 2629)
@@ -116,8 +116,22 @@
}
}
- public void testDeleteFile() throws FileNotFoundException
+ public void testDeleteAquireFile() throws FileNotFoundException, IOException
{
+ // This method creates a file on disk space.
+ SpoolFile sf = SpoolFile.createTempFile("prefix", "suffics", new File(DIR_NAME));
+
+ // Add new holder of file and try to delete a file with holder.
+ sf.acquire("holder");
+ assertFalse("File in use.", sf.delete());
+
+ // Release file and try to delete a file without holder.
+ sf.release("holder");
+ assertTrue("File not in use. It should be deleted", sf.delete());
+ }
+
+ public void testDeleteAbstractFile() throws FileNotFoundException
+ {
// This method not creates a file on disk space.
SpoolFile sf = new SpoolFile(DIR_NAME + FILE_NAME);
@@ -127,6 +141,20 @@
// Now file is free. It can be deleted.
// File on disk does not exist. It will not be removed from disk space.
- assertFalse("Deleted file was not created on the disk.", sf.delete());
+ assertTrue("Deleted file was not created on the disk.", sf.delete());
}
+
+ public void testDeleteExistingFile() throws FileNotFoundException, IOException
+ {
+ // This method creates a file on disk space.
+ SpoolFile sf = SpoolFile.createTempFile("prefix", "suffics", new File(DIR_NAME));
+
+ // Add and release new holder of file.
+ sf.acquire("holder");
+ sf.release("holder");
+
+ // Now file is free. It can be deleted.
+ // File is present on the disk. It will be removed from disk space.
+ assertTrue("File should be removed.", sf.delete());
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java 2010-06-16 09:50:33 UTC (rev 2628)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils/io/TestSwapFile.java 2010-06-16 10:10:30 UTC (rev 2629)
@@ -17,7 +17,10 @@
package org.exoplatform.services.jcr.impl.utils.io;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import org.exoplatform.services.jcr.impl.util.io.SwapFile;
@@ -74,12 +77,27 @@
sf.delete();
}
- public void testDeleteSpoolFile() throws IOException
+ public void testDeleteAbstractSwapFile() throws IOException
{
SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
sf.spoolDone();
// File on disk does not exist. It will not be removed from disk space.
- assertFalse("Deleted file was not created on the disk.", sf.delete());
+ assertTrue("File should be deleted.", sf.delete());
}
+
+ public void testDeleteExistingSwapFile() throws IOException
+ {
+ SwapFile sf = SwapFile.get(new File(DIR_NAME), FILE_NAME);
+
+ // write to file
+ OutputStream out = new FileOutputStream(sf);
+ byte[] outWrite = new byte[]{1, 2, 3};
+ out.write(outWrite);
+ out.close();
+ sf.spoolDone();
+
+ // File is present on the disk. It will be removed from disk space.
+ assertTrue("File should be deleted.", sf.delete());
+ }
}
14 years
exo-jcr SVN: r2628 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: core/query/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 05:50:33 -0400 (Wed, 16 Jun 2010)
New Revision: 2628
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java
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/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java
Log:
EXOJCR-756: replace cache operations on privileged cache operations
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-06-16 08:57:47 UTC (rev 2627)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-16 09:50:33 UTC (rev 2628)
@@ -49,6 +49,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
import org.exoplatform.services.log.ExoLogger;
@@ -71,7 +72,6 @@
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -258,28 +258,12 @@
cache = factory.createCache(config.getLockManager());
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.create();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.create(cache);
// Add the cache loader needed to prevent TimeoutException
addCacheLoader();
- action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.start();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.start(cache);
createStructuredNode(lockRoot);
@@ -768,7 +752,7 @@
public Object execute(LockData newLockData) throws LockException
{
Fqn<String> fqn = makeLockFqn(newLockData.getNodeIdentifier());
- Object oldValue = cache.put(fqn, LOCK_DATA, newLockData);
+ Object oldValue = PrivilegedCacheHelper.put(cache, fqn, LOCK_DATA, newLockData);
if (oldValue == null)
{
throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
@@ -830,15 +814,7 @@
lockRemover.interrupt();
sessionLockManagers.clear();
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.stop();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.stop(cache);
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-06-16 08:57:47 UTC (rev 2627)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-06-16 09:50:33 UTC (rev 2628)
@@ -28,6 +28,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.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
@@ -90,8 +91,7 @@
// try to get pushState parameters, since they are set programmatically only
Boolean pushState = config.getParameterBoolean(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE, false);
- Long pushStateTimeOut =
- config.getParameterTime(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE_TIMEOUT, 10000L);
+ Long pushStateTimeOut = config.getParameterTime(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE_TIMEOUT, 10000L);
singletonStoreProperties.setProperty("pushStateWhenCoordinator", pushState.toString());
singletonStoreProperties.setProperty("pushStateWhenCoordinatorTimeout", pushStateTimeOut.toString());
@@ -115,8 +115,10 @@
cacheLoaderConfig.addIndividualCacheLoaderConfig(individualCacheLoaderConfig);
// insert CacheLoaderConfig
this.cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
- this.cache.create();
- this.cache.start();
+
+ PrivilegedCacheHelper.create(cache);
+ PrivilegedCacheHelper.start(cache);
+
// start will invoke cache listener which will notify handler that mode is changed
IndexerIoMode ioMode =
((CacheSPI)cache).getRPCManager().isCoordinator() ? IndexerIoMode.READ_WRITE : IndexerIoMode.READ_ONLY;
@@ -149,8 +151,8 @@
String id = IdGenerator.generate();
try
{
- cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes,
- parentRemovedNodes));
+ PrivilegedCacheHelper.put(cache, id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes,
+ parentAddedNodes, parentRemovedNodes));
}
catch (CacheException e)
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java 2010-06-16 08:57:47 UTC (rev 2627)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java 2010-06-16 09:50:33 UTC (rev 2628)
@@ -23,6 +23,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -158,7 +159,7 @@
// write to FS
super.write();
// write to cache
- cache.put(namesFqn, LIST_KEY, getNames());
+ PrivilegedCacheHelper.put(cache, namesFqn, LIST_KEY, getNames());
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java 2010-06-16 08:57:47 UTC (rev 2627)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java 2010-06-16 09:50:33 UTC (rev 2628)
@@ -24,6 +24,7 @@
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.IndexUpdateMonitorListener;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -156,7 +157,7 @@
localUpdateInProgress = updateInProgress;
if (persitentUpdate)
{
- cache.put(parametersFqn, PARAMETER_NAME, new Boolean(updateInProgress));
+ PrivilegedCacheHelper.put(cache, parametersFqn, PARAMETER_NAME, new Boolean(updateInProgress));
}
for (IndexUpdateMonitorListener listener : listeners)
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java 2010-06-16 09:50:33 UTC (rev 2628)
@@ -0,0 +1,166 @@
+/*
+ * 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.util.io;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: PrivilegedCacheHelper.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class PrivilegedCacheHelper
+{
+ /**
+ * Start cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void start(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.start();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Stop cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void stop(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.stop();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Create cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void create(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.create();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Put in cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static Object put(final Cache<Serializable, Object> cache, final String fqn, final Serializable key,
+ final Object value) throws CacheException
+ {
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return cache.put(fqn, key, value);
+
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
+ * Put in cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static Object put(final Cache<Serializable, Object> cache, final Fqn fqn, final Serializable key,
+ final Object value) throws CacheException
+ {
+ PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return cache.put(fqn, key, value);
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+}
14 years
exo-jcr SVN: r2627 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/util and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-16 04:57:47 -0400 (Wed, 16 Jun 2010)
New Revision: 2627
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java
Log:
EXOJCR-756: fix
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java 2010-06-16 08:52:38 UTC (rev 2626)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/registration/XmlNodeTypeDataPersister.java 2010-06-16 08:57:47 UTC (rev 2627)
@@ -30,6 +30,9 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.List;
import javax.jcr.RepositoryException;
@@ -135,7 +138,35 @@
{
try
{
- IBindingFactory factory = BindingDirectory.getFactory(NodeTypeValuesList.class);
+ IBindingFactory factory = null;
+ PrivilegedExceptionAction<IBindingFactory> action = new PrivilegedExceptionAction<IBindingFactory>()
+ {
+ public IBindingFactory run() throws Exception
+ {
+ return BindingDirectory.getFactory(NodeTypeValuesList.class);
+ }
+ };
+ try
+ {
+ factory = AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof JiBXException)
+ {
+ throw (JiBXException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
IUnmarshallingContext uctx = factory.createUnmarshallingContext();
NodeTypeValuesList nodeTypeValuesList = (NodeTypeValuesList)uctx.unmarshalDocument(is, null);
List ntvList = nodeTypeValuesList.getNodeTypeValuesList();
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-16 08:52:38 UTC (rev 2626)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/TesterSecurityManager.java 2010-06-16 08:57:47 UTC (rev 2627)
@@ -67,7 +67,8 @@
}
if (fileName.startsWith("Test") || fileName.endsWith("Test.java")
- || fileName.endsWith("TestBase.java") || fileName.equals("Probe.java"))
+ || fileName.endsWith("TestBase.java") || fileName.equals("Probe.java")
+ || fileName.equals("ExportBase.java"))
{
testCode = true;
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java 2010-06-16 08:52:38 UTC (rev 2626)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/security/TestSecurityRepositoryManagment.java 2010-06-16 08:57:47 UTC (rev 2627)
@@ -138,7 +138,7 @@
}
}
- public void testConfigWorkspaceSuccess()
+ public void testConfigWorkspaceSuccess() throws Exception
{
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
@@ -173,9 +173,13 @@
t.printStackTrace();
fail();
}
+
+ // remove configured workspace
+ repository.createWorkspace("testConfigWorkspaceSuccess");
+ repository.internalRemoveWorkspace("testConfigWorkspaceSuccess");
}
- public void testConfigWorkspaceFail()
+ public void testConfigWorkspaceFail() throws Exception
{
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
@@ -215,6 +219,7 @@
public void testCreateWorkspaceSuccess() throws Exception
{
+ // configures workspace for creation
WorkspaceEntry defConfig =
(WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
@@ -250,6 +255,9 @@
t.printStackTrace();
fail();
}
+
+ // remove configured workspace
+ repository.internalRemoveWorkspace("testCreateWorkspaceSuccess");
}
public void testCreateWorkspaceFail()
@@ -281,6 +289,7 @@
public void testInternalRemoveWorkspaceSuccess() throws Exception
{
+ // configures and create workspace
WorkspaceEntry defConfig =
(WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
@@ -453,4 +462,5 @@
fail();
}
}
+
}
14 years