|
2 | 2 |
|
3 | 3 | import com.googlecode.cqengine.IndexedCollection; |
4 | 4 | import com.googlecode.cqengine.attribute.*; |
| 5 | +import com.googlecode.cqengine.attribute.support.SimpleFunction; |
5 | 6 | import com.googlecode.cqengine.query.option.QueryOptions; |
6 | 7 | import com.googlecode.cqengine.resultset.ResultSet; |
7 | 8 | import io.vertx.core.AsyncResult; |
@@ -61,24 +62,25 @@ public IndexedCollection<Value> getDatabase() { |
61 | 62 | return db; |
62 | 63 | } |
63 | 64 |
|
64 | | - @SuppressWarnings("unchecked") |
65 | 65 | public Attribute<Value, String> getAttribute(String fieldName, boolean multiValue) { |
66 | 66 | if (holder.attributes.containsKey(fieldName)) { |
67 | 67 | return holder.attributes.get(fieldName); |
68 | 68 | } else { |
69 | 69 | Attribute<Value, String> attribute; |
70 | 70 |
|
71 | 71 | if (multiValue) { |
72 | | - attribute = new MultiValueAttribute<>((Class<Value>) Generic.class, String.class, fieldName) { |
| 72 | + attribute = new MultiValueAttribute<>(context.valueClass(), String.class, fieldName) { |
73 | 73 | @Override |
74 | 74 | public Iterable<String> getValues(Value indexing, QueryOptions queryOptions) { |
75 | 75 | return Serializer.getValueByPath(indexing, fieldName).stream() |
76 | 76 | .map(item -> (item + ""))::iterator; |
77 | 77 | } |
78 | 78 | }; |
79 | 79 | } else { |
80 | | - attribute = attribute(fieldName, (indexing) -> |
81 | | - (Serializer.getValueByPath(indexing, fieldName).iterator().next() + "")); |
| 80 | + attribute = attribute(context.valueClass(), String.class, fieldName, |
| 81 | + (SimpleFunction<Value, String>) (indexing) -> |
| 82 | + Serializer.getValueByPath(indexing, fieldName).iterator().next() + "" |
| 83 | + ); |
82 | 84 | } |
83 | 85 | holder.attributes.put(fieldName, attribute); |
84 | 86 | return attribute; |
@@ -119,14 +121,6 @@ public void setMapper(Function<Value, Value> mapper) { |
119 | 121 | this.mapper = mapper; |
120 | 122 | } |
121 | 123 |
|
122 | | - /** |
123 | | - * when creating an index on a multivalued attribute a reflective operation is invoked. |
124 | | - * This reflective invocation fails since Value is of generic type. To circumvent this, |
125 | | - * a class that implements Storable, which is the common interface with Value is used. |
126 | | - */ |
127 | | - private abstract class Generic implements Storable { |
128 | | - } |
129 | | - |
130 | 124 | @Override |
131 | 125 | public void get(String key, Handler<AsyncResult<Value>> handler) { |
132 | 126 | context.blocking(blocking -> { |
|
0 commit comments