cancel
Showing results for 
Search instead for 
Did you mean: 

Query an array variable

javialfresco
Champ in-the-making
Champ in-the-making
I read about why variables of type ByteArray cannot be queried and I understand that Blobs cannot be queried in the where-clause but I'm not sure what could be the better approach for my situation:

- I have an  Array variable, lets say: validators = ["a","b","c"] stored in my activiti process

- I want this variable to be an Array because I'm adding - removing elements to this Array with some taskListeners and finally this is the
collection used as the input for a multiinstance task

- Somewhere (before multiinstance) in my business logic I have to search for all the processes with a variable "validators" that contains element "b" and I cannot query this variable because validators array is stored as a ByteArray variable.

Nowadays I'm querying for all process that the variable "validators" is not null (
runtimeService.createProcessInstanceQuery().variableValueLike("validators","%b%")
) and doing some java-processing to get what I'm looking for but this is not an efficient way to do this kind of querys.

I can change this array variable to a String variable and store it like "a,b,c" and then do a variableLike query:
runtimeService.createProcessInstanceQuery().variableValueLike("validators","%b%")
, but in this case I have to do StringToArray and ArrayToString transformations everywhere I need to deal with my validators array.


I cannot find any other way to query my array variable, ¿Am I wrong? ¿Is there a better way to do this kinds of query?

Thanks!

2 REPLIES 2

javialfresco
Champ in-the-making
Champ in-the-making
No one is facing this kind of situation? Am i misusing activiti process variables?

Thanks for your help.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Am i misusing activiti process variables?
I do not think so.

Note 1: Long strings (>4000 chars) are stored in the blobs too.

Note 2: I would say that searching in blob (which serialize java array) depends on the DB vendor. (If the DB implementation supports it you can use it). In other case you have to parse variables in java.

Note 3: You can implement your own type (e.g. for arrays) and store array values there (in the format which can DB query) similar to org.activiti.engine.impl.variable.LongStringType
Regards
Martin