Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lbane committed Mar 20, 2024
1 parent 0d1b457 commit 53bbc96
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EOEnterpriseObject> inserted = ec.insertedObjects();
NSArray<EOEnterpriseObject> updated = ec.updatedObjects();
updated = ERXArrayUtilities.arrayMinusArray(updated, inserted);
NSArray deleted = ec.deletedObjects();
final NSArray<EOEnterpriseObject> 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);
Expand Down
115 changes: 56 additions & 59 deletions Frameworks/EOF/ERIndexing/Sources/er/indexing/ERAutoIndex.java

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Frameworks/EOF/ERIndexing/Sources/er/indexing/ERDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -46,6 +46,7 @@ public Object valueForKey(String key) {
return result;
}

@Override
public void takeValueForKey(Object obj, String key) {
// do nuttin'
}
Expand Down
213 changes: 101 additions & 112 deletions Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndex.java

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,25 +24,26 @@
*/
public class ERIndexer {

private NSArray<ERAutoIndex> _indices;
private NSArray<ERIndex> _indices;

private static final Logger log = LoggerFactory.getLogger(ERIndexer.class);

public ERIndexer(NSArray<ERAutoIndex> indices) {
public ERIndexer(NSArray<ERIndex> indices) {
_indices = indices;
}

public void clear() {
for(Enumeration i = _indices.objectEnumerator(); i.hasMoreElements(); ) {
ERIndex index = (ERIndex) i.nextElement();
for(Enumeration<? extends ERIndex> 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<ERIndex> indicesForEntity(String entityName) {
NSMutableArray<ERIndex> result = new NSMutableArray<>();
for(Enumeration<ERIndex> i = _indices.objectEnumerator(); i.hasMoreElements(); ) {
ERIndex index = i.nextElement();

if(index.handlesEntity(entityName)) {
result.addObject(index);
}
Expand All @@ -57,39 +59,41 @@ public void indexAllObjects(EOEntity entity) {
ec.lock();
try {
EOFetchSpecification fs = new EOFetchSpecification(entity.name(), null, null);
ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs);
ERXFetchSpecificationBatchIterator<EOEnterpriseObject> iterator = new ERXFetchSpecificationBatchIterator<>(fs);
iterator.setEditingContext(ec);
while(iterator.hasNextBatch()) {
NSArray objects = iterator.nextBatch();
NSArray<EOEnterpriseObject> objects = iterator.nextBatch();
if(iterator.currentBatchIndex() % treshhold == 0) {
ec.unlock();
// ec.dispose();
ec = ERXEC.newEditingContext();
ec.lock();
iterator.setEditingContext(ec);
}
for(Enumeration i = incides.objectEnumerator(); i.hasMoreElements(); ) {
ERIndex index = (ERIndex) i.nextElement();
for(Enumeration<ERIndex> 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<EOEntity> 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<EOModel> models = group.models().objectEnumerator(); models.hasMoreElements();) {
EOModel model = models.nextElement();
indexAllObjects(model);
}
}
Expand Down
190 changes: 95 additions & 95 deletions Frameworks/EOF/ERIndexing/Sources/er/indexing/ERIndexing.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,122 +32,122 @@
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<String, ERIndex> 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<String> 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<NSBundle> bundles = NSBundle._allBundlesReally().objectEnumerator(); bundles.hasMoreElements();) {
NSBundle bundle = bundles.nextElement();

// Get list of all files with extension indexModel
NSArray<String> 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<String, Object> dict = (NSDictionary<String, Object>)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<String, NSDictionary<String, Object>> def = (NSDictionary<String, NSDictionary<String, Object>>) NSPropertyListSerialization.propertyListWithPathURL(url);
for (Enumeration<String> keys = def.allKeys().objectEnumerator(); keys.hasMoreElements();) {
String key = keys.nextElement();
NSDictionary<String, Object> 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
*/
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<String, Object> indexDef) {
// Classname for the class that will create the lucene index
String className = (String) indexDef.objectForKey("index");
NSMutableDictionary<String, Object> 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<ERIndex> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public NSArray<ERIAttributeGroup> groups() {
public NSArray<ERIAttribute> allAttributes() {
NSMutableArray<ERIAttribute> result = new NSMutableArray<>();
for (ERIAttributeGroup group : groups()) {
result.addObjectsFromArray(attributes());
result.addObjectsFromArray(group.attributes());
}
return result;
}
Expand All @@ -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());
}
}
Loading

0 comments on commit 53bbc96

Please sign in to comment.