Optimization of Map Queries



I am having loads and loads of occurrences of something like

((com.test.MyEntity) $1.map.get('com.test.MyEntity')).someProperty
((com.test.MyEntity) $1.map.get('com.test.MyEntity')).someOtherProperty
((com.test.MyEntity) $1.map.get('com.test.MyEntity')).someMoreProperties

I need to use full qualified names for casting as well as for the map keys because same entity simple names may occur multiple times.

Now I've got two questions:

1) Will odb smart enough to cache the map.get(..) result(s) once to not query the map again and again for each test in my query?

2) Is there anything I could do for shortening the query string? I guess there's no such thing as a "temporary" variable for being used in the query..

I am creating the query using criteriabuilder, then I am converting it to string and replace all occurrences with the proper map.get(..) and (..) casting code.


The current implementation of the  Map's get method in queries is not very efficient, and in addition the result is not reused but calculated for every occurrence. Maybe introducing a variable using JOIN that is bound to the expression could help (at least the method will be invoked once).
About the query length - you may try setting shorter entity names (in @Entity) and use them instead of the fully qualified names.
ObjectDB Support


How would such a join variable look like? And how to create it using criteria api?

We do have heavy usage of maps so I'd appreciate any optimization.. (though I guess, in object oriented models, usage of map is something pretty regular..)



Binding a variable to a complex expression is an ObjectDB extension, so it might not be available in criteria queries.

Maps are indeed commonly used by ObjectDB users, but mainly for storage and retrieval or navigation, and rarely in queries. Actually support of querying maps in ObjectDB has to be improved.

If you post a sample test that demonstrates a heavy query on maps - it could be served to improve ObjectDB in the specific scenario that represents your needs.

ObjectDB Support


Well, our use case is pretty "simple". We do have some kind of modular system that allows to extend existing entities with new properties etc. at runtime. To realize this, we do have a Map<String, BaseEmbeddedClass> property on our main entities. To request the property of an extension (which is heavily used) we need to do a ((Cast_To_Proper_Extension_Type) entity.map.get('Fully_Qualified_Name_Of_ExtensionType_')).Property_Of_Extension_Type.

Most properties we query for are located in such extension types and as such, we'll have a LOT of map calls in our resulting query...