Menu

#22 Support Accessor using Map's name value pair

open
nobody
None
5
2012-03-05
2012-03-05
Anonymous
No

Currently, the accessor is based on Java Bean convention getter. Is it possible to have the accessor work with Map's name value pair without using Bean? This is to avoid generating Java Bean class from the data set. I have different kinds of data set and each data set uses it's own attribute/value pairs. To be able to use JoSQL, I have to create/generate a Java Bean class for each data set.

For each data set to search via JoSQL:
Current: List<MyDataObject>
Wanted: List<Map<String, String>> (So far, I am only interested in string values.)

I could use in memory DB like H2 and dynamically generate DB schema based on attributes. But with JoSQL, I cannot create Java Bean class at runtime.

Is this something worth to consider? Or is there already a way to do this? I just started to look at JoSQL and plan to use it in our project. It's a great fit so far since we only use basic query and the performance is very good: under 1s query for 1M objects.

Thanks in advance!
Bo

Discussion

  • nihongye

    nihongye - 2012-12-12

    en,i try to do something like below:
    define the function:
    import java.util.HashMap;
    import java.util.Map;

    public class MapValue {
    private Map<String,String[]> expressions = new HashMap<String,String[]>();

    @SuppressWarnings("rawtypes")
    public Object f(Map map,String expression){
    String[] properties = expressions.get(expression);
    if(properties == null){
    properties = expression.split("\\.");
    expressions.put(expression, properties);
    }
    for(int i = 0; i < properties.length - 1;i++){
    map = (Map) map.get(properties[i]);
    if(map == null){
    break;
    }
    }
    if(map != null){
    return map.get(properties[properties.length - 1]);
    }
    return map;
    }
    }

    //use the function
    Query q = new Query();
    q.addFunctionHandler(new MapValue());
    String sql = "select * from java.util.Map "
    + " where f(:_currobj,'school.name') like 'a%'" + " and f(:_currobj,'age') > 10";

     

Log in to post a comment.