390 words

Optimization of Map Queries

#1
2012-01-18 07:13

hi!

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.

Alex

quasado
quasado's picture
Joined on 2011-04-30
User Post #83
#2
2012-01-18 07:19
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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #866
#3
2012-01-18 07:25

Hi,

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..)

Alex

quasado
quasado's picture
Joined on 2011-04-30
User Post #84
#4
2012-01-18 07:27

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #867
#5
2012-01-18 07:41

Hi,

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...

 

Alex

quasado
quasado's picture
Joined on 2011-04-30
User Post #85

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel