jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r778613 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: ConsistencyCheck.java MultiIndex.java SearchIndex.java
Date Tue, 26 May 2009 08:22:46 GMT
Author: jukka
Date: Tue May 26 08:22:46 2009
New Revision: 778613

URL: http://svn.apache.org/viewvc?rev=778613&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform

More query code generification as I get myself familiar with the latest status of the code.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java?rev=778613&r1=778612&r2=778613&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
Tue May 26 08:22:46 2009
@@ -28,7 +28,6 @@
 
 import javax.jcr.RepositoryException;
 import java.io.IOException;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Set;
@@ -66,12 +65,13 @@
     /**
      * All the document UUIDs within the index.
      */
-    private Set documentUUIDs;
+    private Set<UUID> documentUUIDs;
 
     /**
      * List of all errors.
      */
-    private final List errors = new ArrayList();
+    private final List<ConsistencyCheckError> errors =
+        new ArrayList<ConsistencyCheckError>();
 
     /**
      * Private constructor.
@@ -109,8 +109,7 @@
             return;
         }
         int notRepairable = 0;
-        for (Iterator it = errors.iterator(); it.hasNext();) {
-            ConsistencyCheckError error = (ConsistencyCheckError) it.next();
+        for (ConsistencyCheckError error : errors) {
             try {
                 if (error.repairable()) {
                     error.repair();
@@ -139,8 +138,8 @@
      * Returns the errors detected by the consistency check.
      * @return the errors detected by the consistency check.
      */
-    List getErrors() {
-        return new ArrayList(errors);
+    List<ConsistencyCheckError> getErrors() {
+        return new ArrayList<ConsistencyCheckError>(errors);
     }
 
     /**
@@ -149,9 +148,9 @@
      */
     private void run() throws IOException {
         // UUIDs of multiple nodes in the index
-        Set multipleEntries = new HashSet();
+        Set<UUID> multipleEntries = new HashSet<UUID>();
         // collect all documents UUIDs
-        documentUUIDs = new HashSet();
+        documentUUIDs = new HashSet<UUID>();
         CachingMultiIndexReader reader = index.getIndexReader();
         try {
             for (int i = 0; i < reader.maxDoc(); i++) {
@@ -177,8 +176,8 @@
         }
 
         // create multiple entries errors
-        for (Iterator it = multipleEntries.iterator(); it.hasNext();) {
-            errors.add(new MultipleEntries((UUID) it.next()));
+        for (UUID uuid : multipleEntries) {
+            errors.add(new MultipleEntries(uuid));
         }
 
         reader = index.getIndexReader();
@@ -226,7 +225,7 @@
         // remember as fallback
         String uuid = node.getNodeId().toString();
         StringBuffer path = new StringBuffer();
-        List elements = new ArrayList();
+        List<ChildNodeEntry> elements = new ArrayList<ChildNodeEntry>();
         try {
             while (node.getParentId() != null) {
                 NodeId parentId = node.getParentId();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=778613&r1=778612&r2=778613&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Tue May 26 08:22:46 2009
@@ -97,7 +97,7 @@
     /**
      * Names of index directories that can be deleted.
      */
-    private final Set deletable = new HashSet();
+    private final Set<String> deletable = new HashSet<String>();
 
     /**
      * List of open persistent indexes. This list may also contain an open
@@ -105,7 +105,8 @@
      * registered with indexNames and <b>must not</b> be used in regular index
      * operations (delete node, etc.)!
      */
-    private final List indexes = new ArrayList();
+    private final List<PersistentIndex> indexes =
+        new ArrayList<PersistentIndex>();
 
     /**
      * The internal namespace mappings of the query manager.
@@ -191,9 +192,9 @@
     private IndexingQueue indexingQueue;
 
     /**
-     * Set&lt;NodeId> of uuids that should not be indexed.
+     * Identifiers of nodes that should not be indexed.
      */
-    private final Set excludedIDs;
+    private final Set<NodeId> excludedIDs;
 
     /**
      * The next transaction id.
@@ -219,18 +220,17 @@
      * Creates a new MultiIndex.
      *
      * @param handler the search handler
-     * @param excludedIDs   Set&lt;NodeId> that contains uuids that should not
-     *                      be indexed nor further traversed.
+     * @param excludedIDs identifiers of nodes that should
+     *                    neither be indexed nor further traversed
      * @throws IOException if an error occurs
      */
-    MultiIndex(SearchIndex handler,
-               Set excludedIDs) throws IOException {
+    MultiIndex(SearchIndex handler, Set<NodeId> excludedIDs) throws IOException {
         this.directoryManager = handler.getDirectoryManager();
         this.indexDir = directoryManager.getDirectory(".");
         this.handler = handler;
         this.cache = new DocNumberCache(handler.getCacheSize());
         this.redoLog = new RedoLog(indexDir);
-        this.excludedIDs = new HashSet(excludedIDs);
+        this.excludedIDs = new HashSet<NodeId>(excludedIDs);
         this.nsMappings = handler.getNamespaceMappings();
 
         if (indexNames.exists(indexDir)) {
@@ -522,34 +522,33 @@
      * @return the <code>IndexReaders</code>.
      * @throws IOException if an error occurs acquiring the index readers.
      */
-    synchronized IndexReader[] getIndexReaders(String[] indexNames, IndexListener listener)
-            throws IOException {
-        Set names = new HashSet(Arrays.asList(indexNames));
-        Map indexReaders = new HashMap();
+    synchronized IndexReader[] getIndexReaders(
+            String[] indexNames, IndexListener listener) throws IOException {
+        Set<String> names = new HashSet<String>(Arrays.asList(indexNames));
+        Map<ReadOnlyIndexReader, PersistentIndex> indexReaders =
+            new HashMap<ReadOnlyIndexReader, PersistentIndex>();
 
         try {
-            for (Iterator it = indexes.iterator(); it.hasNext();) {
-                PersistentIndex index = (PersistentIndex) it.next();
+            for (PersistentIndex index : indexes) {
                 if (names.contains(index.getName())) {
                     indexReaders.put(index.getReadOnlyIndexReader(listener), index);
                 }
             }
         } catch (IOException e) {
             // release readers obtained so far
-            for (Iterator it = indexReaders.entrySet().iterator(); it.hasNext();) {
-                Map.Entry entry = (Map.Entry) it.next();
-                ReadOnlyIndexReader reader = (ReadOnlyIndexReader) entry.getKey();
+            for (Map.Entry<ReadOnlyIndexReader, PersistentIndex> entry
+                    : indexReaders.entrySet()) {
                 try {
-                    reader.release();
+                    entry.getKey().release();
                 } catch (IOException ex) {
                     log.warn("Exception releasing index reader: " + ex);
                 }
-                ((PersistentIndex) entry.getValue()).resetListener();
+                entry.getValue().resetListener();
             }
             throw e;
         }
 
-        return (IndexReader[]) indexReaders.keySet().toArray(new IndexReader[indexReaders.size()]);
+        return indexReaders.keySet().toArray(new IndexReader[indexReaders.size()]);
     }
 
     /**
@@ -564,8 +563,7 @@
     synchronized PersistentIndex getOrCreateIndex(String indexName)
             throws IOException {
         // check existing
-        for (Iterator it = indexes.iterator(); it.hasNext();) {
-            PersistentIndex idx = (PersistentIndex) it.next();
+        for (PersistentIndex idx : indexes) {
             if (idx.getName().equals(indexName)) {
                 return idx;
             }
@@ -601,8 +599,7 @@
      */
     synchronized boolean hasIndex(String indexName) throws IOException {
         // check existing
-        for (Iterator it = indexes.iterator(); it.hasNext();) {
-            PersistentIndex idx = (PersistentIndex) it.next();
+        for (PersistentIndex idx : indexes) {
             if (idx.getName().equals(indexName)) {
                 return true;
             }
@@ -625,7 +622,7 @@
      */
     void replaceIndexes(String[] obsoleteIndexes,
                         PersistentIndex index,
-                        Collection deleted)
+                        Collection<Term> deleted)
             throws IOException {
 
         if (handler.isInitializeHierarchyCache()) {
@@ -646,10 +643,9 @@
                     executeAndLog(new Start(Action.INTERNAL_TRANS_REPL_INDEXES));
                 }
                 // delete obsolete indexes
-                Set names = new HashSet(Arrays.asList(obsoleteIndexes));
-                for (Iterator it = names.iterator(); it.hasNext();) {
+                Set<String> names = new HashSet<String>(Arrays.asList(obsoleteIndexes));
+                for (String indexName : names) {
                     // do not try to delete indexes that are already gone
-                    String indexName = (String) it.next();
                     if (indexNames.contains(indexName)) {
                         executeAndLog(new DeleteIndex(getTransactionId(), indexName));
                     }
@@ -662,8 +658,7 @@
                 executeAndLog(new AddIndex(getTransactionId(), index.getName()));
 
                 // delete documents in index
-                for (Iterator it = deleted.iterator(); it.hasNext();) {
-                    Term id = (Term) it.next();
+                for (Term id : deleted) {
                     index.removeDocument(id);
                 }
                 index.commit();
@@ -725,7 +720,8 @@
             // some other read thread might have created the reader in the
             // meantime -> check again
             if (multiReader == null) {
-                List readerList = new ArrayList();
+                List<ReadOnlyIndexReader> readerList =
+                    new ArrayList<ReadOnlyIndexReader>();
                 for (int i = 0; i < indexes.size(); i++) {
                     PersistentIndex pIdx = (PersistentIndex) indexes.get(i);
                     if (indexNames.contains(pIdx.getName())) {
@@ -734,7 +730,7 @@
                 }
                 readerList.add(volatileIndex.getReadOnlyIndexReader());
                 ReadOnlyIndexReader[] readers =
-                        (ReadOnlyIndexReader[]) readerList.toArray(new ReadOnlyIndexReader[readerList.size()]);
+                    readerList.toArray(new ReadOnlyIndexReader[readerList.size()]);
                 multiReader = new CachingMultiIndexReader(readers, cache);
             }
             multiReader.acquire();
@@ -1082,9 +1078,7 @@
             checkIndexingQueue(true);
         }
         checkVolatileCommit();
-        List children = node.getChildNodeEntries();
-        for (Iterator it = children.iterator(); it.hasNext();) {
-            ChildNodeEntry child = (ChildNodeEntry) it.next();
+        for (ChildNodeEntry child : node.getChildNodeEntries()) {
             Path childPath = PATH_FACTORY.create(path, child.getName(),
                     child.getIndex(), false);
             NodeState childState = null;
@@ -1106,8 +1100,8 @@
      */
     private void attemptDelete() {
         synchronized (deletable) {
-            for (Iterator it = deletable.iterator(); it.hasNext(); ) {
-                String indexName = (String) it.next();
+            for (Iterator<String> it = deletable.iterator(); it.hasNext(); ) {
+                String indexName = it.next();
                 if (directoryManager.delete(indexName)) {
                     it.remove();
                 } else {
@@ -1770,8 +1764,7 @@
          */
         public void execute(MultiIndex index) throws IOException {
             // get index if it exists
-            for (Iterator it = index.indexes.iterator(); it.hasNext();) {
-                PersistentIndex idx = (PersistentIndex) it.next();
+            for (PersistentIndex idx : index.indexes) {
                 if (idx.getName().equals(indexName)) {
                     idx.close();
                     index.deleteIndex(idx);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=778613&r1=778612&r2=778613&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Tue May 26 08:22:46 2009
@@ -73,7 +73,6 @@
 import java.io.IOException;
 import java.io.File;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -344,7 +343,7 @@
     /**
      * The excerpt provider class. Implements {@link ExcerptProvider}.
      */
-    private Class excerptProviderClass = DefaultHTMLExcerpt.class;
+    private Class<?> excerptProviderClass = DefaultHTMLExcerpt.class;
 
     /**
      * The path to the indexing configuration file.
@@ -366,12 +365,12 @@
      * The indexing configuration class.
      * Implements {@link IndexingConfiguration}.
      */
-    private Class indexingConfigurationClass = IndexingConfigurationImpl.class;
+    private Class<?> indexingConfigurationClass = IndexingConfigurationImpl.class;
 
     /**
      * The class that implements {@link SynonymProvider}.
      */
-    private Class synonymProviderClass;
+    private Class<?> synonymProviderClass;
 
     /**
      * The currently set synonym provider.
@@ -402,7 +401,7 @@
     /**
      * The class that implements {@link SpellChecker}.
      */
-    private Class spellCheckerClass;
+    private Class<?> spellCheckerClass;
 
     /**
      * The spell checker for this query handler or <code>null</code> if none
is
@@ -467,7 +466,7 @@
             throw new IOException("SearchIndex requires 'path' parameter in configuration!");
         }
 
-        Set excludedIDs = new HashSet();
+        Set<NodeId> excludedIDs = new HashSet<NodeId>();
         if (context.getExcludedNodeId() != null) {
             excludedIDs.add(context.getExcludedNodeId());
         }
@@ -522,12 +521,11 @@
                 if (autoRepair) {
                     check.repair(true);
                 } else {
-                    List errors = check.getErrors();
+                    List<ConsistencyCheckError> errors = check.getErrors();
                     if (errors.size() == 0) {
                         log.info("No errors detected.");
                     }
-                    for (Iterator it = errors.iterator(); it.hasNext();) {
-                        ConsistencyCheckError err = (ConsistencyCheckError) it.next();
+                    for (ConsistencyCheckError err : errors) {
                         log.info(err.toString());
                     }
                 }
@@ -976,7 +974,7 @@
      */
     protected SortField[] createSortFields(Path[] orderProps,
                                            boolean[] orderSpecs) {
-        List sortFields = new ArrayList();
+        List<SortField> sortFields = new ArrayList<SortField>();
         for (int i = 0; i < orderProps.length; i++) {
             if (orderProps[i].getLength() == 1
                     && NameConstants.JCR_SCORE.equals(orderProps[i].getNameElement().getName()))
{
@@ -989,7 +987,7 @@
                 sortFields.add(new SortField(orderProps[i].getString(), scs, !orderSpecs[i]));
             }
         }
-        return (SortField[]) sortFields.toArray(new SortField[sortFields.size()]);
+        return sortFields.toArray(new SortField[sortFields.size()]);
     }
 
     /**
@@ -1100,7 +1098,7 @@
     protected DirectoryManager createDirectoryManager()
             throws IOException {
         try {
-            Class clazz = Class.forName(directoryManagerClass);
+            Class<?> clazz = Class.forName(directoryManagerClass);
             if (!DirectoryManager.class.isAssignableFrom(clazz)) {
                 throw new IOException(directoryManagerClass +
                         " is not a DirectoryManager implementation");
@@ -1582,7 +1580,7 @@
      */
     public void setAnalyzer(String analyzerClassName) {
         try {
-            Class analyzerClass = Class.forName(analyzerClassName);
+            Class<?> analyzerClass = Class.forName(analyzerClassName);
             analyzer.setDefaultAnalyzer((Analyzer) analyzerClass.newInstance());
         } catch (Exception e) {
             log.warn("Invalid Analyzer class: " + analyzerClassName, e);
@@ -1877,7 +1875,7 @@
      */
     public void setExcerptProviderClass(String className) {
         try {
-            Class clazz = Class.forName(className);
+            Class<?> clazz = Class.forName(className);
             if (ExcerptProvider.class.isAssignableFrom(clazz)) {
                 excerptProviderClass = clazz;
             } else {
@@ -1922,7 +1920,7 @@
      */
     public void setIndexingConfigurationClass(String className) {
         try {
-            Class clazz = Class.forName(className);
+            Class<?> clazz = Class.forName(className);
             if (IndexingConfiguration.class.isAssignableFrom(clazz)) {
                 indexingConfigurationClass = clazz;
             } else {
@@ -1952,7 +1950,7 @@
      */
     public void setSynonymProviderClass(String className) {
         try {
-            Class clazz = Class.forName(className);
+            Class<?> clazz = Class.forName(className);
             if (SynonymProvider.class.isAssignableFrom(clazz)) {
                 synonymProviderClass = clazz;
             } else {
@@ -1986,7 +1984,7 @@
      */
     public void setSpellCheckerClass(String className) {
         try {
-            Class clazz = Class.forName(className);
+            Class<?> clazz = Class.forName(className);
             if (SpellChecker.class.isAssignableFrom(clazz)) {
                 spellCheckerClass = clazz;
             } else {
@@ -2055,7 +2053,7 @@
      */
     public void setSimilarityClass(String className) {
         try {
-            Class similarityClass = Class.forName(className);
+            Class<?> similarityClass = Class.forName(className);
             similarity = (Similarity) similarityClass.newInstance();
         } catch (Exception e) {
             log.warn("Invalid Similarity class: " + className, e);



Mime
View raw message