diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAttributeIndex.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAttributeIndex.java index 97699d5c3aa..2face295216 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAttributeIndex.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAttributeIndex.java @@ -4,6 +4,7 @@ import java.net.MalformedURLException; import com.webobjects.eocontrol.EOEditingContext; +import com.webobjects.eocontrol.EOEnterpriseObject; import com.webobjects.foundation.NSArray; import com.webobjects.foundation.NSForwardException; import com.webobjects.foundation.NSNotification; @@ -23,16 +24,16 @@ public void _handleChanges(NSNotification n) { String notificationName = n.name(); if (notificationName.equals(ERXEC.EditingContextWillSaveChangesNotification)) { ec.processRecentChanges(); - NSArray inserted = ec.insertedObjects(); - NSArray updated = ec.updatedObjects(); + final NSArray inserted = ec.insertedObjects(); + NSArray updated = ec.updatedObjects(); updated = ERXArrayUtilities.arrayMinusArray(updated, inserted); - NSArray deleted = ec.deletedObjects(); + final NSArray deleted = ec.deletedObjects(); Transaction transaction = new Transaction(ec); activeChanges.put(ec, transaction); - } else if (notificationName.equals(ERXEC.EditingContextDidSaveChangesNotification)) { + } else if (notificationName.equals(EOEditingContext.EditingContextDidSaveChangesNotification)) { Transaction transaction = activeChanges.get(ec); if (transaction != null) { activeChanges.remove(ec); diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAutoIndex.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAutoIndex.java index e41d31a3ce4..c433d32f04f 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAutoIndex.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAutoIndex.java @@ -14,6 +14,7 @@ import com.webobjects.eocontrol.EOFetchSpecification; import com.webobjects.eocontrol.EOKeyGlobalID; import com.webobjects.eocontrol.EOKeyValueQualifier; +import com.webobjects.eocontrol.EOObjectStore; import com.webobjects.eocontrol.EOQualifier; import com.webobjects.foundation.NSArray; import com.webobjects.foundation.NSDictionary; @@ -85,9 +86,9 @@ protected class ConfigurationEntry { public boolean active = false; - public NSMutableArray keys = new NSMutableArray(); + public NSMutableArray keys = new NSMutableArray<>(); - public NSMutableArray notificationKeys = new NSMutableArray(); + public NSMutableArray notificationKeys = new NSMutableArray<>(); @Override public String toString() { @@ -109,7 +110,7 @@ protected class Configuration { // Each entity has an entry where the key is the entity name and the object is a ConfigurationEntry for that entity private final NSMutableDictionary configuration = new NSMutableDictionary<>(); - protected void initFromDictionary(NSDictionary indexDef) { + protected void initFromDictionary(NSDictionary indexDef) { String store = (String) indexDef.objectForKey("store"); // Set the index storage location @@ -119,7 +120,7 @@ protected void initFromDictionary(NSDictionary indexDef) { configuration.clear(); // Get the list of entities specififed in the indexModel definition - NSArray entities = (NSArray) indexDef.objectForKey("entities"); + NSArray entities = (NSArray)indexDef.objectForKey("entities"); // Creates IndexAttributes, one for each entry in indexModel.properties createAttributes(indexDef); @@ -136,14 +137,14 @@ protected void initFromDictionary(NSDictionary indexDef) { * in the indexModel defintion. Each property is a key or keypath. * @param indexDef */ - protected void createAttributes(NSDictionary indexDef) { + protected void createAttributes(NSDictionary indexDef) { // Get the properties dictionary which is one element of the indexModel dictionary - NSDictionary properties = (NSDictionary) indexDef.objectForKey("properties"); + NSDictionary properties = (NSDictionary) indexDef.objectForKey("properties"); // For each property in indexModel, create configuration attributes - for (Enumeration names = properties.keyEnumerator(); names.hasMoreElements();) { - String propertyName = (String) names.nextElement(); - NSDictionary propertyDefinition = (NSDictionary) properties.objectForKey(propertyName); + for (Enumeration names = properties.keyEnumerator(); names.hasMoreElements();) { + String propertyName = names.nextElement(); + NSDictionary propertyDefinition = (NSDictionary) properties.objectForKey(propertyName); createAttribute(propertyName, propertyDefinition); } } @@ -152,7 +153,7 @@ protected void createAttributes(NSDictionary indexDef) { * @param entityName entity to be indexed * @param keys attributes (keys or keypaths) to be indexed */ - protected ConfigurationEntry configureEntity(String entityName, NSArray keys) { + protected ConfigurationEntry configureEntity(String entityName, NSArray keys) { // Get ConfigurationEntry for the entity if it already exists ConfigurationEntry config = configuration.objectForKey(entityName); @@ -164,8 +165,8 @@ protected ConfigurationEntry configureEntity(String entityName, NSArray keys) { } EOEntity source = ERXEOAccessUtilities.entityNamed(null, entityName); - for (Enumeration e = keys.objectEnumerator(); e.hasMoreElements();) { - String keyPath = (String) e.nextElement(); + for (Enumeration e = keys.objectEnumerator(); e.hasMoreElements();) { + String keyPath = e.nextElement(); configureKeyPath(config, keyPath, source); } return config; @@ -177,16 +178,15 @@ private ConfigurationEntry configureKeyPath(ConfigurationEntry config, String ke EORelationship rel = source._relationshipForPath(key); if (rel != null) { if (rel.isFlattened()) { - ConfigurationEntry c = configureKeyPath(config, rel.definition() + (rest != null ? "." + rest : ""), source); - return c; + return configureKeyPath(config, rel.definition() + (rest != null ? "." + rest : ""), source); } EOEntity destinationEntity = rel.destinationEntity(); ConfigurationEntry destinationConfiguration; if (rest != null) { - destinationConfiguration = configureEntity(destinationEntity.name(), new NSArray(rest)); + destinationConfiguration = configureEntity(destinationEntity.name(), new NSArray<>(rest)); } else { - destinationConfiguration = configureEntity(destinationEntity.name(), new NSArray()); + destinationConfiguration = configureEntity(destinationEntity.name(), NSArray.emptyArray()); } String inverseName = rel.anyInverseRelationship().name(); destinationConfiguration.notificationKeys.addObject(inverseName); @@ -213,26 +213,22 @@ public void clear() { protected class AutoTransactionHandler extends TransactionHandler { @Override - public void submit(Transaction transaction) { - if(false) { - _queue.enqueue(transaction); - } else { - index(transaction); - } + public void submit(Transaction transaction) { + index(transaction); } @Override - public void _handleChanges(NSNotification n) { + public void _handleChanges(NSNotification n) { EOEditingContext ec = (EOEditingContext) n.object(); if (ec.parentObjectStore() == ec.rootObjectStore()) { String notificationName = n.name(); if (notificationName.equals(ERXEC.EditingContextWillSaveChangesNotification)) { ec.processRecentChanges(); - NSArray inserted = ec.insertedObjects(); - NSArray updated = ec.updatedObjects(); + NSArray inserted = ec.insertedObjects(); + NSArray updated = ec.updatedObjects(); updated = ERXArrayUtilities.arrayMinusArray(updated, inserted); - NSArray deleted = ec.deletedObjects(); + NSArray deleted = ec.deletedObjects(); Transaction transaction = new Transaction(ec); @@ -256,15 +252,15 @@ public void _handleChanges(NSNotification n) { addedHandledObjects.addObjectsFromArray(directObjects); NSArray indirectObjects; - indirectObjects = indexableObjectsForObjects(EOEditingContext.UpdatedKey, updated); + indirectObjects = indexableObjectsForObjects(EOObjectStore.UpdatedKey, updated); deletedHandledObjects.addObjectsFromArray(indirectObjects); addedHandledObjects.addObjectsFromArray(indirectObjects); - indirectObjects = indexableObjectsForObjects(EOEditingContext.InsertedKey, inserted); + indirectObjects = indexableObjectsForObjects(EOObjectStore.InsertedKey, inserted); deletedHandledObjects.addObjectsFromArray(indirectObjects); addedHandledObjects.addObjectsFromArray(indirectObjects); - indirectObjects = indexableObjectsForObjects(EOEditingContext.DeletedKey, deleted); + indirectObjects = indexableObjectsForObjects(EOObjectStore.DeletedKey, deleted); deletedHandledObjects.addObjectsFromArray(indirectObjects); addedHandledObjects.addObjectsFromArray(indirectObjects); @@ -273,7 +269,7 @@ public void _handleChanges(NSNotification n) { activeChanges.put(ec, transaction); - } else if (notificationName.equals(ERXEC.EditingContextDidSaveChangesNotification)) { + } else if (notificationName.equals(EOEditingContext.EditingContextDidSaveChangesNotification)) { Transaction transaction = activeChanges.get(ec); if (transaction != null) { activeChanges.remove(ec); @@ -296,30 +292,30 @@ private NSArray handledObjects(NSArray o return result; } - protected NSArray indexableObjectsForObjects(String type, NSArray objects) { - NSMutableSet result = new NSMutableSet(); + protected NSArray indexableObjectsForObjects(String type, NSArray objects) { + NSMutableSet result = new NSMutableSet<>(); for (EOEnterpriseObject eo : objects) { - NSArray targetObjects = indexableObjectsForObject(type, eo); + NSArray targetObjects = indexableObjectsForObject(type, eo); result.addObjectsFromArray(targetObjects); } return result.allObjects(); } - private final NSMutableSet _warned = new NSMutableSet(); + private final NSMutableSet _warned = new NSMutableSet<>(); - protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject object) { + protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject object) { ERXGenericRecord eo = (ERXGenericRecord) object; EOEditingContext ec = eo.editingContext(); - NSMutableSet result = new NSMutableSet(); + NSMutableSet result = new NSMutableSet<>(); String entityName = eo.entityName(); ConfigurationEntry config = _configuration.entryForKey(entityName); if (config != null) { if (!config.active) { - for (Enumeration e1 = config.notificationKeys.objectEnumerator(); e1.hasMoreElements();) { - String key = (String) e1.nextElement(); + for (Enumeration e1 = config.notificationKeys.objectEnumerator(); e1.hasMoreElements();) { + String key = e1.nextElement(); Object value = null; - if (type.equals(EOEditingContext.DeletedKey)) { + if (type.equals(EOObjectStore.DeletedKey)) { value = ec.committedSnapshotForObject(eo); } @@ -330,7 +326,7 @@ protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject obje } else { if (eo.isNewObject()) { if (!_warned.containsObject(entityName)) { - log.error("We currently don't support unsaved related objects for this entity: " + entityName); + log.error("We currently don't support unsaved related objects for this entity: {}", entityName); _warned.addObject(entityName); } } else { @@ -343,10 +339,10 @@ protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject obje // ec.arrayFaultWithSourceGlobalID(sourceGlobalID, // rel.name(), ec); EOFetchSpecification fs = new EOFetchSpecification(rel.destinationEntity().name(), null, null); - NSMutableArray qualifiers = new NSMutableArray(rel.joins().count()); - NSDictionary pk = source.primaryKeyForGlobalID(sourceGlobalID); - for (Iterator iterator = rel.joins().iterator(); iterator.hasNext();) { - EOJoin join = (EOJoin) iterator.next(); + NSMutableArray qualifiers = new NSMutableArray<>(rel.joins().count()); + NSDictionary pk = source.primaryKeyForGlobalID(sourceGlobalID); + for (Iterator iterator = rel.joins().iterator(); iterator.hasNext();) { + EOJoin join = iterator.next(); Object pkValue = pk.objectForKey(join.sourceAttribute().name()); EOKeyValueQualifier qualifier = new EOKeyValueQualifier(join.destinationAttribute().name(), EOQualifier.QualifierOperatorEqual, pkValue); qualifiers.addObject(qualifier); @@ -356,14 +352,14 @@ protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject obje } } if (value != null) { - NSArray eos = (value instanceof EOEnterpriseObject ? new NSArray(value) : (NSArray) value); + NSArray eos = ((value instanceof EOEnterpriseObject eoValue) ? new NSArray(eoValue) : (NSArray) value); for (EOEnterpriseObject target : eos) { - NSArray targetObjects = indexableObjectsForObject(EOEditingContext.UpdatedKey, target); + NSArray targetObjects = indexableObjectsForObject(EOObjectStore.UpdatedKey, target); result.addObjectsFromArray(targetObjects); } } if (!result.isEmpty() && log.isDebugEnabled()) { - log.debug("re-index: " + eo + "->" + result); + log.debug("re-index: {}->{}", eo, result); } } } else { @@ -381,7 +377,7 @@ protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject obje private final Configuration _configuration = new Configuration(); - public ERAutoIndex(String name, NSDictionary indexDef) { + public ERAutoIndex(String name, NSDictionary indexDef) { super(name); // Ensures that the first instance of ERAutoIndex creates the singleton thread @@ -391,43 +387,43 @@ public ERAutoIndex(String name, NSDictionary indexDef) { _queue = new ERXAsyncQueue() { @Override - public void process(Transaction transaction) { + public void process(Transaction transaction) { transaction.handler().index(transaction); } }; - + // Set the name of the thread _queue.setName(KEY); - + // Start the thread _queue.start(); } } - - _entities = new NSMutableSet(); + + _entities = new NSMutableSet<>(); _configuration.initFromDictionary(indexDef); setTransactionHandler(new AutoTransactionHandler()); } - protected NSSet entities() { + protected NSSet entities() { return _entities; } public void reindexAllObjects() { clear(); - for (Enumeration names = entities().objectEnumerator(); names.hasMoreElements();) { - String entityName = (String) names.nextElement(); + for (Enumeration names = entities().objectEnumerator(); names.hasMoreElements();) { + String entityName = names.nextElement(); long start = System.currentTimeMillis(); int treshhold = 10; EOEditingContext ec = ERXEC.newEditingContext(); ec.lock(); try { EOFetchSpecification fs = new EOFetchSpecification(entityName, null, null); - ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs); + ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator<>(fs); iterator.setEditingContext(ec); while (iterator.hasNextBatch()) { - NSArray objects = iterator.nextBatch(); + NSArray objects = iterator.nextBatch(); if (iterator.currentBatchIndex() % treshhold == 0) { ec.unlock(); // ec.dispose(); @@ -442,10 +438,11 @@ public void reindexAllObjects() { } finally { ec.unlock(); } - log.info("Indexing " + entityName + " took: " + (System.currentTimeMillis() - start) + " ms"); + log.info("Indexing {} took: {} ms", entityName, (System.currentTimeMillis() - start)); } } + @Override protected boolean handlesEntity(String name) { ConfigurationEntry config = _configuration.entryForKey(name); return config != null && config.active; diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERDocument.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERDocument.java index 192fdcde452..209651edb34 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERDocument.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERDocument.java @@ -32,12 +32,12 @@ public void setScore(Float score) { public EOKeyGlobalID eoKeyGlobalId() { String gidString = _doc.get(GID); - EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); - return gid; + return ERXKeyGlobalID.fromString(gidString).globalID(); } // KVC + @Override public Object valueForKey(String key) { Object result = _doc.get(key); if (result == null) { @@ -46,6 +46,7 @@ public Object valueForKey(String key) { return result; } + @Override public void takeValueForKey(Object obj, String key) { // do nuttin' } diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndex.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndex.java index b2298959055..9e63e332aa0 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndex.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndex.java @@ -2,7 +2,8 @@ import java.io.File; import java.io.IOException; -import java.net.URL; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.text.Format; import java.util.Date; import java.util.Enumeration; @@ -21,7 +22,6 @@ import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.Field.TermVector; import org.apache.lucene.document.NumberTools; -import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; @@ -80,11 +80,11 @@ public class ERIndex { protected Logger log; - public static String IndexingStartedNotification = "ERIndexingStartedNotification"; + public static final String IndexingStartedNotification = "ERIndexingStartedNotification"; - public static String IndexingEndedNotification = "ERIndexingEndedNotification"; + public static final String IndexingEndedNotification = "ERIndexingEndedNotification"; - public static String IndexingFailedNotification = "ERIndexingFailedNotification"; + public static final String IndexingFailedNotification = "ERIndexingFailedNotification"; private static final String GID = "EOGlobalID"; @@ -96,16 +96,16 @@ public class IndexDocument implements NSKeyValueCoding { private final Document _document; - private final NSMutableDictionary _values = new NSMutableDictionary<>(); - public IndexDocument(Document document) { _document = document; } + @Override public void takeValueForKey(Object value, String key) { _document.getField(key).setValue(key); } + @Override public Object valueForKey(String key) { return _document.get(key); } @@ -153,12 +153,12 @@ protected class IndexAttribute { * @param name the property name (a key or keypath) * @param dict the property definition form indexModel */ - IndexAttribute(ERIndex index, String name, NSDictionary dict) { + IndexAttribute(ERIndex index, String name, NSDictionary dict) { _name = name; _termVector = (TermVector) classValue(dict, "termVector", TermVector.class, "YES"); _store = (Store) classValue(dict, "store", Store.class, "NO"); _index = (Index) classValue(dict, "index", Index.class, "ANALYZED"); - String analyzerClass = (String) dict.objectForKey("analyzer"); + String analyzerClass = dict.objectForKey("analyzer"); if (analyzerClass == null) { analyzerClass = StandardAnalyzer.class.getName(); } @@ -166,12 +166,12 @@ protected class IndexAttribute { if (_analyzer == null && name.matches("\\w+_(\\w+)")) { // String locale = name.substring(name.lastIndexOf('_') + 1); } - _format = (Format) create((String) dict.objectForKey("format")); - String numberFormat = (String) dict.objectForKey("numberformat"); + _format = (Format) create(dict.objectForKey("format")); + String numberFormat = dict.objectForKey("numberformat"); if (numberFormat != null) { _format = new NSNumberFormatter(numberFormat); } - String dateformat = (String) dict.objectForKey("dateformat"); + String dateformat = dict.objectForKey("dateformat"); if (dateformat != null) { _format = new NSTimestampFormatter(dateformat); } @@ -180,25 +180,21 @@ protected class IndexAttribute { private Object create(String className) { if (className != null) { try { - Class c = ERXPatcher.classForName(className); - return c.newInstance(); - } catch (InstantiationException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); - } catch (IllegalAccessException e) { + Class c = ERXPatcher.classForName(className); + return c.getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw NSForwardException._runtimeExceptionForThrowable(e); - } + } } return null; } - private Object classValue(NSDictionary dict, String key, Class c, String defaultValue) { - Object result; - String code = (String) dict.objectForKey(key); + private Object classValue(NSDictionary dict, String key, Class c, String defaultValue) { + String code = dict.objectForKey(key); if (code == null) { code = defaultValue; } - result = ERXKeyValueCodingUtilities.classValueForKey(c, code); - return result; + return ERXKeyValueCodingUtilities.classValueForKey(c, code); } public TermVector termVector() { @@ -225,14 +221,14 @@ public String formatValue(Object value) { if (_format != null) { return _format.format(value); } - if (value instanceof Number) { - return NumberTools.longToString(((Number) value).longValue()); + if (value instanceof Number numberValue) { + return NumberTools.longToString(numberValue.longValue()); } - if (value instanceof Date) { - return DateTools.dateToString((Date) value, Resolution.MILLISECOND); + if (value instanceof Date dateValue) { + return DateTools.dateToString(dateValue, Resolution.MILLISECOND); } - if (value instanceof NSArray) { - return ((NSArray) value).componentsJoinedByString(" "); + if (value instanceof NSArray arrayValue) { + return arrayValue.componentsJoinedByString(" "); } return (value != null ? value.toString() : null); } @@ -259,14 +255,14 @@ protected class Job { private final Command _command; - private final NSArray _objects; + private final NSArray _objects; - public Job(Command command, NSArray objects) { + public Job(Command command, NSArray objects) { _command = command; _objects = objects; } - public NSArray objects() { + public NSArray objects() { return _objects; } @@ -293,7 +289,7 @@ public void clear() { _clear = true; } - public void addJob(Command command, NSArray objects) { + public void addJob(Command command, NSArray objects) { if (objects.count() > 0) { _objectCount += objects.count(); _jobs.addObject(new Job(command, objects)); @@ -309,11 +305,13 @@ public NSArray jobs() { } @Override - public String toString() { + public String toString() { if (hasClear()) { return "Transaction@" + hashCode() + " clear"; } - return "Transaction@" + (editingContext() != null ? editingContext().hashCode() : null) + "@" + hashCode() + " jobs: " + jobs().count() + " objects: " + _objectCount; + return "Transaction@" + (editingContext() != null ? editingContext().hashCode() : null) + "@" + hashCode() + + " jobs: " + jobs().count() + + " objects: " + _objectCount; } public boolean hasClear() { @@ -345,18 +343,18 @@ private void registerNotification(String notificationName, String selectorName) protected void registerNotifications() { registerNotification(ERXEC.EditingContextWillSaveChangesNotification, "_handleChanges"); - registerNotification(ERXEC.EditingContextDidSaveChangesNotification, "_handleChanges"); + registerNotification(EOEditingContext.EditingContextDidSaveChangesNotification, "_handleChanges"); registerNotification(ERXEC.EditingContextDidRevertChanges, "_handleChanges"); registerNotification(ERXEC.EditingContextFailedToSaveChanges, "_handleChanges"); } - protected void addObjectsToIndex(Transaction transaction, NSArray objects) { - NSArray added = addedDocumentsForObjects(objects); + protected void addObjectsToIndex(Transaction transaction, NSArray objects) { + NSArray added = addedDocumentsForObjects(objects); transaction.addJob(Command.ADD, added); } protected void deleteObjectsFromIndex(Transaction transaction, NSArray objects) { - NSArray deleted = deletedTermsForObjects(objects); + NSArray deleted = deletedTermsForObjects(objects); transaction.addJob(Command.DELETE, deleted); } @@ -375,31 +373,31 @@ synchronized void index(Transaction transaction) { return; } long start = System.currentTimeMillis(); - log.info("Running " + transaction); + log.info("Running {}", transaction); if (!create && !indexDirectory().fileExists("segments.gen")) { log.error("segments did not exist but create wasn't called"); create = true; } IndexWriter writer = new IndexWriter(indexDirectory(), analyzer(), create, IndexWriter.MaxFieldLength.UNLIMITED); for (Job job : transaction.jobs()) { - log.info("Indexing: " + job.command() + " " + job.objects().count()); + log.info("Indexing: {} {}", job.command(), job.objects().count()); if (job.command() == Command.DELETE) { - for (Enumeration iter = job.objects().objectEnumerator(); iter.hasMoreElements();) { - Term term = (Term) iter.nextElement(); + for (Enumeration iter = job.objects().objectEnumerator(); iter.hasMoreElements();) { + Term term = (Term)iter.nextElement(); writer.deleteDocuments(term); } } else if (job.command() == Command.ADD) { - for (Enumeration iter = job.objects().objectEnumerator(); iter.hasMoreElements();) { - Document document = (Document) iter.nextElement(); + for (Enumeration iter = job.objects().objectEnumerator(); iter.hasMoreElements();) { + Document document = (Document)iter.nextElement(); writer.addDocument(document, analyzer()); } } - log.info("Done: " + job.command() + " " + job.objects().count()); + log.info("Done: {} {}", job.command(), job.objects().count()); } writer.flush(); writer.close(); NSNotificationCenter.defaultCenter().postNotification(IndexingEndedNotification, transaction); - log.info("Finished in " + (System.currentTimeMillis() - start) / 1000 + "s: " + transaction); + log.info("Finished in {}s: {}", (System.currentTimeMillis() - start) / 1000, transaction); } catch (IOException e) { NSNotificationCenter.defaultCenter().postNotification(IndexingFailedNotification, transaction); throw NSForwardException._runtimeExceptionForThrowable(e); @@ -425,7 +423,7 @@ protected ERIndex(String name) { indices.setObjectForKey(this, name); } - public void addObjectsToIndex(EOEditingContext ec, NSArray objects) { + public void addObjectsToIndex(EOEditingContext ec, NSArray objects) { Transaction transaction = new Transaction(ec); _handler.addObjectsToIndex(transaction, objects); _handler.submit(transaction); @@ -457,7 +455,7 @@ protected Analyzer analyzer() { return wrapper; } - public void addAttribute(String propertyName, NSDictionary propertyDefinition) { + public void addAttribute(String propertyName, NSDictionary propertyDefinition) { createAttribute(propertyName, propertyDefinition); } @@ -468,9 +466,9 @@ public void addAttribute(String propertyName, NSDictionary propertyDefinition) { * @param propertyDefinition * @return the new {@link IndexAttribute} */ - protected IndexAttribute createAttribute(String propertyName, NSDictionary propertyDefinition) { + protected IndexAttribute createAttribute(String propertyName, NSDictionary propertyDefinition) { IndexAttribute attribute = new IndexAttribute(this, propertyName, propertyDefinition); - NSMutableDictionary attributes = _attributes.mutableClone(); + NSMutableDictionary attributes = _attributes.mutableClone(); attributes.setObjectForKey(attribute, propertyName); _attributes = attributes.immutableClone(); return attribute; @@ -480,7 +478,7 @@ private Directory indexDirectory() { if(_indexDirectory == null) { try { if (_store.startsWith("file://")) { - File indexDirectory = new File(new URL(_store).getFile()); + File indexDirectory = new File(URI.create(_store)); _indexDirectory = FSDirectory.open(indexDirectory); } else { EOEditingContext ec = ERXEC.newEditingContext(); @@ -503,7 +501,7 @@ private Directory indexDirectory() { private IndexReader _reader; private IndexSearcher _searcher; - private IndexReader indexReader() throws CorruptIndexException, IOException { + private IndexReader indexReader() throws IOException { if (_reader == null) { _reader = IndexReader.open(indexDirectory(), true); // ^^^ readOnly @@ -516,7 +514,7 @@ private IndexReader indexReader() throws CorruptIndexException, IOException { return _reader; } - public IndexSearcher indexSearcher() throws CorruptIndexException, IOException { + public IndexSearcher indexSearcher() throws IOException { IndexReader indexReader = indexReader(); return _searcher; } @@ -545,11 +543,11 @@ protected boolean handlesObject(EOEnterpriseObject eo) { return true; } - protected NSArray addedDocumentsForObjects(NSArray objects) { - NSMutableArray documents = new NSMutableArray(); + protected NSArray addedDocumentsForObjects(NSArray objects) { + NSMutableArray documents = new NSMutableArray<>(); - for (Enumeration e = objects.objectEnumerator(); e.hasMoreElements();) { - EOEnterpriseObject eo = (EOEnterpriseObject) e.nextElement(); + for (Enumeration e = objects.objectEnumerator(); e.hasMoreElements();) { + EOEnterpriseObject eo = e.nextElement(); if (handlesObject(eo)) { Document doc = createDocumentForObject(eo); if (doc != null) { @@ -569,7 +567,7 @@ protected Document createDocumentForObject(EOEnterpriseObject eo) { Object value = eo.valueForKeyPath(key); if (log.isDebugEnabled()) { - log.info(key + "->" + value); + log.info("{}->{}", key, value); } String stringValue = info.formatValue(value); @@ -582,10 +580,10 @@ protected Document createDocumentForObject(EOEnterpriseObject eo) { } protected NSArray deletedTermsForObjects(NSArray objects) { - NSMutableArray terms = new NSMutableArray(); + NSMutableArray terms = new NSMutableArray<>(); Term term; - for (Enumeration e = objects.objectEnumerator(); e.hasMoreElements();) { - EOEnterpriseObject eo = (EOEnterpriseObject) e.nextElement(); + for (Enumeration e = objects.objectEnumerator(); e.hasMoreElements();) { + EOEnterpriseObject eo = e.nextElement(); if (handlesObject(eo)) { term = createTerm(eo); if (term != null) { @@ -603,15 +601,9 @@ protected Term createTerm(EOEnterpriseObject eo) { return term; } - private String gidStringForObject(EOEnterpriseObject eo) { + private static String gidStringForObject(EOEnterpriseObject eo) { EOKeyGlobalID gid = ((ERXGenericRecord) eo).permanentGlobalID(); - String pk = ERXKeyGlobalID.globalIDForGID(gid).asString(); - return pk; - } - - private EOEnterpriseObject objectForGidString(EOEditingContext ec, String gidString) { - EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); - return ec.faultForGlobalID(gid, ec); + return ERXKeyGlobalID.globalIDForGID(gid).asString(); } private Query queryForQualifier(EOQualifier qualifier) throws ParseException { @@ -622,12 +614,10 @@ private Query queryForQualifier(EOQualifier qualifier) throws ParseException { private Query queryForString(String fieldName, String queryString) throws ParseException { Analyzer analyzer = attributeNamed(fieldName).analyzer(); QueryParser parser = new QueryParser(Version.LUCENE_29, fieldName, analyzer); - Query query = parser.parse(queryString); - - return query; + return parser.parse(queryString); } - private Query queryForString(String queryString) throws ParseException { + private Query queryForString(String queryString) { //TODO return null; } @@ -643,13 +633,13 @@ private NSArray findGlobalIDs(Query query, Filter filter, Sort so long startTime = System.currentTimeMillis(); sort = sort == null ? new Sort() : sort; TopFieldDocs topFielsDocs = searcher.search(query, filter, end, sort); - log.info("Searched for: " + query + " in " + (System.currentTimeMillis() - startTime) + " ms"); + log.info("Searched for: {} in {} ms", query, (System.currentTimeMillis() - startTime)); for (int i = start; i < topFielsDocs.scoreDocs.length; i++) { String gidString = searcher.doc(topFielsDocs.scoreDocs[i].doc).getField(GID).stringValue(); EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); result.addObject(gid); } - log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - startTime) + " ms"); + log.info("Returning {} after {} ms", result.count(), System.currentTimeMillis() - startTime); return result; } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); @@ -657,19 +647,19 @@ private NSArray findGlobalIDs(Query query, Filter filter, Sort so } private NSArray findGlobalIDs(Query query) { - NSMutableArray result = new NSMutableArray(); + NSMutableArray result = new NSMutableArray<>(); long start = System.currentTimeMillis(); try { Searcher searcher = indexSearcher(); Hits hits = searcher.search(query); - log.info("Searched for: " + query + " in " + (System.currentTimeMillis() - start) + " ms"); - for (Iterator iter = hits.iterator(); iter.hasNext();) { - Hit hit = (Hit) iter.next(); + log.info("Searched for: {} in {} ms", query, (System.currentTimeMillis() - start)); + for (Iterator iter = hits.iterator(); iter.hasNext();) { + Hit hit = iter.next(); String gidString = hit.getDocument().getField(GID).stringValue(); EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); result.addObject(gid); } - log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - start) + " ms"); + log.info("Returning {} after {} ms", result.count(), System.currentTimeMillis() - start); return result; } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); @@ -681,12 +671,8 @@ public NSArray findObjects(EOEditingContext ec, Qu } public NSArray findGlobalIDs(String queryString) { - try { - Query query = queryForString(queryString); - return findGlobalIDs(query); - } catch (ParseException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); - } + Query query = queryForString(queryString); + return findGlobalIDs(query); } public NSArray findGlobalIDs(EOQualifier qualifier) { @@ -699,19 +685,19 @@ public NSArray findGlobalIDs(EOQualifier qualifier) { } public ScoreDoc[] findScoreDocs(Query query, int hitsPerPage) { - ScoreDoc[] hits = null; - long start = System.currentTimeMillis(); + ScoreDoc[] hits = null; + long start = System.currentTimeMillis(); try { - - Searcher searcher = indexSearcher(); - TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true); - searcher.search(query, collector); - hits = collector.topDocs().scoreDocs; - - log.debug("Returning " + hits.length + " after " + (System.currentTimeMillis() - start) + " ms"); + + Searcher searcher = indexSearcher(); + TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true); + searcher.search(query, collector); + hits = collector.topDocs().scoreDocs; + + log.debug("Returning {} after {} ms", hits.length, System.currentTimeMillis() - start); return hits; } catch (IOException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); + throw NSForwardException._runtimeExceptionForThrowable(e); } } @@ -733,7 +719,7 @@ public NSArray findTermStringsForPrefix(String field, String prefix) { } public IndexDocument findDocument(EOKeyGlobalID globalID) { - NSMutableArray result = new NSMutableArray(); + NSMutableArray result = new NSMutableArray<>(); long start = System.currentTimeMillis(); try { Searcher searcher = indexSearcher(); @@ -742,12 +728,14 @@ public IndexDocument findDocument(EOKeyGlobalID globalID) { query.add(new TermQuery(new Term(GID, pk)), Occur.MUST); Hits hits = searcher.search(query); - log.info("Searched for: " + query.toString(GID) + " in " + (System.currentTimeMillis() - start) + " ms"); - for (Iterator iter = hits.iterator(); iter.hasNext();) { - Hit hit = (Hit) iter.next(); + if (log.isInfoEnabled()) { + log.info("Searched for: {} in {} ms", query.toString(GID), System.currentTimeMillis() - start); + } + for (Iterator iter = hits.iterator(); iter.hasNext();) { + Hit hit = iter.next(); result.addObject(hit.getDocument()); } - log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - start) + " ms"); + log.info("Returning {} after {} ms", result.count(), System.currentTimeMillis() - start); } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); } @@ -774,18 +762,14 @@ public NSArray findObjects(EOEditingContext ec, EO } } - public NSArray findObjects(EOEditingContext ec, String queryString) { - try { - Query query = queryForString(queryString); - NSArray gids = findGlobalIDs(query); - return ERXEOControlUtilities.faultsForGlobalIDs(ec, gids); - } catch (ParseException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); - } + public NSArray findObjects(EOEditingContext ec, String queryString) { + Query query = queryForString(queryString); + NSArray gids = findGlobalIDs(query); + return ERXEOControlUtilities.faultsForGlobalIDs(ec, gids); } public NSArray terms(String fieldName) { - NSMutableSet result = new NSMutableSet(); + NSMutableSet result = new NSMutableSet<>(); TermEnum terms = null; try { IndexReader reader = indexReader(); @@ -803,7 +787,7 @@ public NSArray terms(String fieldName) { try { terms.close(); } catch (IOException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); + log.error("Could not close terms", e); } } } @@ -825,4 +809,9 @@ public IndexDocument createDocumentForGlobalID(EOKeyGlobalID globalID) { public static ERIndex indexNamed(String key) { return indices.objectForKey(key); } + + protected boolean handlesEntity(String entityName) + { + return true; + } } diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexer.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexer.java index 3b0f7284b06..3be8f48b7b2 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexer.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexer.java @@ -9,6 +9,7 @@ import com.webobjects.eoaccess.EOModel; import com.webobjects.eoaccess.EOModelGroup; import com.webobjects.eocontrol.EOEditingContext; +import com.webobjects.eocontrol.EOEnterpriseObject; import com.webobjects.eocontrol.EOFetchSpecification; import com.webobjects.foundation.NSArray; import com.webobjects.foundation.NSMutableArray; @@ -23,25 +24,26 @@ */ public class ERIndexer { - private NSArray _indices; + private NSArray _indices; private static final Logger log = LoggerFactory.getLogger(ERIndexer.class); - public ERIndexer(NSArray indices) { + public ERIndexer(NSArray indices) { _indices = indices; } public void clear() { - for(Enumeration i = _indices.objectEnumerator(); i.hasMoreElements(); ) { - ERIndex index = (ERIndex) i.nextElement(); + for(Enumeration i = _indices.objectEnumerator(); i.hasMoreElements(); ) { + ERIndex index = i.nextElement(); index.clear(); } } - public NSArray indicesForEntity(String entityName) { - NSMutableArray result = new NSMutableArray(); - for(Enumeration i = _indices.objectEnumerator(); i.hasMoreElements(); ) { - ERAutoIndex index = (ERAutoIndex) i.nextElement(); + public NSArray indicesForEntity(String entityName) { + NSMutableArray result = new NSMutableArray<>(); + for(Enumeration i = _indices.objectEnumerator(); i.hasMoreElements(); ) { + ERIndex index = i.nextElement(); + if(index.handlesEntity(entityName)) { result.addObject(index); } @@ -57,10 +59,10 @@ public void indexAllObjects(EOEntity entity) { ec.lock(); try { EOFetchSpecification fs = new EOFetchSpecification(entity.name(), null, null); - ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs); + ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator<>(fs); iterator.setEditingContext(ec); while(iterator.hasNextBatch()) { - NSArray objects = iterator.nextBatch(); + NSArray objects = iterator.nextBatch(); if(iterator.currentBatchIndex() % treshhold == 0) { ec.unlock(); // ec.dispose(); @@ -68,28 +70,30 @@ public void indexAllObjects(EOEntity entity) { ec.lock(); iterator.setEditingContext(ec); } - for(Enumeration i = incides.objectEnumerator(); i.hasMoreElements(); ) { - ERIndex index = (ERIndex) i.nextElement(); + for(Enumeration i = incides.objectEnumerator(); i.hasMoreElements(); ) { + ERIndex index = i.nextElement(); index.addObjectsToIndex(ec, objects); } } } finally { ec.unlock(); } - log.info("Indexing {} took: {}ms", entity.name(), System.currentTimeMillis() - start); + if (log.isInfoEnabled()) { + log.info("Indexing {} took: {} ms", entity.name(), System.currentTimeMillis() - start); + } } } public void indexAllObjects(EOModel model) { - for (Enumeration entities = model.entities().objectEnumerator(); entities.hasMoreElements();) { - EOEntity entity = (EOEntity) entities.nextElement(); + for (Enumeration entities = model.entities().objectEnumerator(); entities.hasMoreElements();) { + EOEntity entity = entities.nextElement(); indexAllObjects(entity); } } public void indexAllObjects(EOModelGroup group) { - for (Enumeration models = group.models().objectEnumerator(); models.hasMoreElements();) { - EOModel model = (EOModel) models.nextElement(); + for (Enumeration models = group.models().objectEnumerator(); models.hasMoreElements();) { + EOModel model = models.nextElement(); indexAllObjects(model); } } diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexing.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexing.java index a7aa8f2b5cc..fae90236191 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexing.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexing.java @@ -32,80 +32,80 @@ import er.extensions.foundation.ERXStringUtilities; public class ERIndexing extends ERXFrameworkPrincipal { - private static final Logger log = LoggerFactory.getLogger(ERIndexing.class); + @SuppressWarnings("hiding") + private static final Logger log = LoggerFactory.getLogger(ERIndexing.class); - // Master dictionary of indices - NSMutableDictionary indices = ERXMutableDictionary.synchronizedDictionary(); - - public final static Class REQUIRES[] = new Class[] {ERXExtensions.class}; + // Master dictionary of indices + NSMutableDictionary indices = ERXMutableDictionary.synchronizedDictionary(); + + @SuppressWarnings("rawtypes") + public static final Class[] REQUIRES = new Class[] {ERXExtensions.class}; static { setUpFrameworkPrincipalClass (ERIndexing.class); } - private File _indexRoot; - - private File indexRoot() { - if(_indexRoot == null) { - String name = ERXProperties.stringForKeyWithDefault("er.indexing.ERIndexModel.rootDirectory", "/tmp"); - _indexRoot = new File(name); - } - return _indexRoot; - } - - /** - * Searches all bundles for *.indexModel resources files and dserializes the index definitions and adds - * the index definitions to the master dictionary of application indices - */ - public void loadIndexDefinitions() { - // Check every bundle (app and frameworks) - for (Enumeration bundles = NSBundle._allBundlesReally().objectEnumerator(); bundles.hasMoreElements();) { - NSBundle bundle = (NSBundle) bundles.nextElement(); - - // Get list of all files with extension indexModel - NSArray files = bundle.resourcePathsForResources("indexModel", null); - for (String file : files) { - URL url = bundle.pathURLForResourcePath(file); - - // Get the name of the indexModel file withut the directory path and without the file extension - String name = url.toString().replaceAll(".*?/(\\w+)\\.indexModel$", "$1"); - if(url != null) { - - // If in development mode, observe the indexModel file for changes - // so that the index can be recreated - if(ERXApplication.isDevelopmentModeSafe()) { - NSSelector selector = ERXSelectorUtilities.notificationSelector("fileDidChange"); - ERXFileNotificationCenter.defaultCenter().addObserver(this, selector, url.getFile()); - } - - // Get contents of indexModel file - String string = ERXStringUtilities.stringFromResource(name, "indexModel", bundle); - - // Convert file contents into nested NSDictionary - NSDictionary dict = (NSDictionary)NSPropertyListSerialization.propertyListFromString(string); - - // Create the lucene index with name and dictionary definition - addIndex(name, dict); - log.info("Added index: {}", name); - } - } - } - } - - public void fileDidChange(NSNotification n) throws MalformedURLException { - File file = (File) n.object(); - loadModel(file.toURI().toURL()); - } - - private void loadModel(URL url) { - NSDictionary def = (NSDictionary) NSPropertyListSerialization.propertyListWithPathURL(url); - for (Enumeration keys = def.allKeys().objectEnumerator(); keys.hasMoreElements();) { - String key = (String) keys.nextElement(); - NSDictionary indexDef = (NSDictionary) def.objectForKey(key); - addIndex(key, indexDef); - } - } - + private File _indexRoot; + + private File indexRoot() { + if(_indexRoot == null) { + String name = ERXProperties.stringForKeyWithDefault("er.indexing.ERIndexModel.rootDirectory", "/tmp"); + _indexRoot = new File(name); + } + return _indexRoot; + } + + /** + * Searches all bundles for *.indexModel resources files and dserializes the index definitions and adds + * the index definitions to the master dictionary of application indices + */ + public void loadIndexDefinitions() { + // Check every bundle (app and frameworks) + for (Enumeration bundles = NSBundle._allBundlesReally().objectEnumerator(); bundles.hasMoreElements();) { + NSBundle bundle = bundles.nextElement(); + + // Get list of all files with extension indexModel + NSArray files = bundle.resourcePathsForResources("indexModel", null); + for (String file : files) { + URL url = bundle.pathURLForResourcePath(file); + + // Get the name of the indexModel file withut the directory path and without the file extension + String name = url.toString().replaceAll(".*?/(\\w+)\\.indexModel$", "$1"); + + // If in development mode, observe the indexModel file for changes + // so that the index can be recreated + if(ERXApplication.isDevelopmentModeSafe()) { + NSSelector selector = ERXSelectorUtilities.notificationSelector("fileDidChange"); + ERXFileNotificationCenter.defaultCenter().addObserver(this, selector, url.getFile()); + } + + // Get contents of indexModel file + String string = ERXStringUtilities.stringFromResource(name, "indexModel", bundle); + + // Convert file contents into nested NSDictionary + NSDictionary dict = (NSDictionary)NSPropertyListSerialization.propertyListFromString(string); + + // Create the lucene index with name and dictionary definition + addIndex(name, dict); + log.info("Added index: {}", name); + } + } + } + + public void fileDidChange(NSNotification n) throws MalformedURLException { + File file = (File) n.object(); + loadModel(file.toURI().toURL()); + } + + private void loadModel(URL url) { + NSDictionary> def = (NSDictionary>) NSPropertyListSerialization.propertyListWithPathURL(url); + for (Enumeration keys = def.allKeys().objectEnumerator(); keys.hasMoreElements();) { + String key = keys.nextElement(); + NSDictionary indexDef = def.objectForKey(key); + addIndex(key, indexDef); + } + } + /** * @param key the name of the index * @param index the indexer instance having the name of the index and the index definition from the indexModel file @@ -113,41 +113,41 @@ private void loadModel(URL url) { protected void addIndex(String key, ERIndex index) { indices.setObjectForKey(index, key); } - - /** - * @param key the name of the index - * @param indexDef the dictionary containing the index definition (usually deserialized from the indexModel file) - */ - private void addIndex(String key, NSDictionary indexDef) { - // Classname for the class that will create the lucene index - String className = (String) indexDef.objectForKey("index"); - NSMutableDictionary dict = indexDef.mutableClone(); - - // If index store not defined, default to index named the dsame as the indexModel file in the indexRoot directory - if(!dict.containsKey("store")) { - try { - dict.setObjectForKey(new File(indexRoot(), key).toURI().toURL().toString(), "store"); - } catch (MalformedURLException e) { - throw NSForwardException._runtimeExceptionForThrowable(e); - } - } - - // Create the class that will create the index. Defaults to ERAutoIndex - ERIndex index; - if (className != null) { - Class c = ERXPatcher.classForName(className); + + /** + * @param key the name of the index + * @param indexDef the dictionary containing the index definition (usually deserialized from the indexModel file) + */ + private void addIndex(String key, NSDictionary indexDef) { + // Classname for the class that will create the lucene index + String className = (String) indexDef.objectForKey("index"); + NSMutableDictionary dict = indexDef.mutableClone(); + + // If index store not defined, default to index named the dsame as the indexModel file in the indexRoot directory + if(!dict.containsKey("store")) { + try { + dict.setObjectForKey(new File(indexRoot(), key).toURI().toURL().toString(), "store"); + } catch (MalformedURLException e) { + throw NSForwardException._runtimeExceptionForThrowable(e); + } + } + + // Create the class that will create the index. Defaults to ERAutoIndex + ERIndex index; + if (className != null) { + Class c = ERXPatcher.classForName(className); index = (ERIndex) _NSUtilities.instantiateObject(c, new Class[] { String.class, NSDictionary.class }, new Object[] { key, dict }, true, false); } else { index = new ERAutoIndex(key, dict); } - - // Add the index - addIndex(key, index); + + // Add the index + addIndex(key, index); } @Override public void finishInitialization() { - // load index definition files into indices + // load index definition files into indices loadIndexDefinitions(); } diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIAttributeGroup.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIAttributeGroup.java index aeb70f658a6..2a054c180d2 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIAttributeGroup.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIAttributeGroup.java @@ -47,7 +47,7 @@ public NSArray groups() { public NSArray allAttributes() { NSMutableArray result = new NSMutableArray<>(); for (ERIAttributeGroup group : groups()) { - result.addObjectsFromArray(attributes()); + result.addObjectsFromArray(group.attributes()); } return result; } @@ -62,12 +62,10 @@ public ERIAttribute attributeForName(String name) { } public ERIDocument documentForGlobalID(EOEditingContext editingContext, EOKeyGlobalID permanentGlobalID) { - ERIDocument document = new ERIDocument(this, permanentGlobalID); - return document; + return new ERIDocument(this, permanentGlobalID); } public synchronized ERIndex index() { - ERAttributeIndex index = ERAttributeIndex.indexNamed(name()); - return index; + return ERAttributeIndex.indexNamed(name()); } } diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIDocument.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIDocument.java index 06c5330f778..2f4df53dcce 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIDocument.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/attributes/ERIDocument.java @@ -33,12 +33,14 @@ private ERIAttribute attributeForName(String key) { return null; } + @Override public void takeValueForKey(Object value, String key) { willRead(); String stringValue = attributeForName(key).formatValue(value); document().takeValueForKey(stringValue, key); } + @Override public Object valueForKey(String key) { willRead(); if(isRead()) { diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIDirectory.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIDirectory.java index 8b4e98cd8b9..b6327321c6d 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIDirectory.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIDirectory.java @@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory; import com.webobjects.eocontrol.EOEditingContext; -import com.webobjects.foundation.NSArray; import com.webobjects.foundation.NSMutableDictionary; import er.extensions.eof.ERXEOControlUtilities; @@ -24,7 +23,8 @@ public class ERIDirectory extends _ERIDirectory { */ private static final long serialVersionUID = 1L; - private static final Logger log = LoggerFactory.getLogger(ERIDirectory.class); + @SuppressWarnings("hiding") + private static final Logger log = LoggerFactory.getLogger(ERIDirectory.class); public static final ERIDirectoryClazz clazz = new ERIDirectoryClazz(); @@ -97,7 +97,8 @@ public long fileModified(String name) throws IOException { } } - @Override + @Deprecated + @Override public String[] list() throws IOException { editingContext().lock(); try { @@ -117,7 +118,8 @@ public IndexInput openInput(String name) throws IOException { } } - @Override + @Deprecated + @Override public void renameFile(String from, String to) throws IOException { editingContext().lock(); try { @@ -186,7 +188,7 @@ public String name() { } } - private NSMutableDictionary locks = new NSMutableDictionary(); + private NSMutableDictionary locks = new NSMutableDictionary<>(); @Override public void clearLock(String s) throws IOException { @@ -223,7 +225,7 @@ public IndexOutput createOutput(String s) throws IOException { if (file == null) { file = createFile(s); } - return fileForName(s).createOutput(); + return file.createOutput(); } public ERIFile createFile(String s) { @@ -261,9 +263,10 @@ public long fileModified(String s) throws IOException { return fileForName(s).timestamp(); } - @Override + @Deprecated + @Override public String[] list() throws IOException { - return ((NSArray) files().valueForKeyPath(ERIFile.Key.NAME)).toArray(new String[0]); + return files().stream().map(_ERIFile::name).toArray(String[]::new); } @Override @@ -281,7 +284,8 @@ public IndexInput openInput(String s) throws IOException { } } - @Override + @Deprecated + @Override public void renameFile(String s, String s1) throws IOException { fileForName(s).setName(s1); editingContext().saveChanges(); diff --git a/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIFile.java b/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIFile.java index 7b8a482b075..c082e2a815e 100644 --- a/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIFile.java +++ b/Frameworks/EOF/ERIndexing/Sources/er/indexing/storage/ERIFile.java @@ -21,6 +21,7 @@ public class ERIFile extends _ERIFile { */ private static final long serialVersionUID = 1L; + @SuppressWarnings("hiding") private static final Logger log = LoggerFactory.getLogger(ERIFile.class); public static final ERIFileClazz clazz = new ERIFileClazz(); diff --git a/Frameworks/EOF/ERIndexing/pom.xml b/Frameworks/EOF/ERIndexing/pom.xml index 6b968432aac..ac82fc68fe8 100644 --- a/Frameworks/EOF/ERIndexing/pom.xml +++ b/Frameworks/EOF/ERIndexing/pom.xml @@ -30,6 +30,12 @@ wonder.core ERPrototypes + + + org.eclipse.jdt + org.eclipse.jdt.annotation + 2.3.0 + Sources