Search in sources :

Example 1 with ValueExtractor

use of com.hazelcast.query.extractor.ValueExtractor in project hazelcast by hazelcast.

the class ExtractorHelperTest method instantiate_extractors_withCustomClassLoader.

@Test
public void instantiate_extractors_withCustomClassLoader() {
    // GIVEN
    MapAttributeConfig iqExtractor = new MapAttributeConfig("iq", "com.hazelcast.query.impl.getters.ExtractorHelperTest$IqExtractor");
    MapAttributeConfig nameExtractor = new MapAttributeConfig("name", "com.hazelcast.query.impl.getters.ExtractorHelperTest$NameExtractor");
    Config config = new Config();
    // For other custom class loaders (from OSGi bundles, for example)
    ClassLoader customClassLoader = getClass().getClassLoader();
    config.setClassLoader(customClassLoader);
    // WHEN
    Map<String, ValueExtractor> extractors = instantiateExtractors(asList(iqExtractor, nameExtractor));
    // THEN
    assertThat(extractors.get("iq"), instanceOf(IqExtractor.class));
    assertThat(extractors.get("name"), instanceOf(NameExtractor.class));
}
Also used : MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) Config(com.hazelcast.config.Config) MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) Test(org.junit.Test)

Example 2 with ValueExtractor

use of com.hazelcast.query.extractor.ValueExtractor in project hazelcast by hazelcast.

the class ExtractorHelperTest method instantiate_extractors.

@Test
public void instantiate_extractors() {
    // GIVEN
    MapAttributeConfig iqExtractor = new MapAttributeConfig("iq", "com.hazelcast.query.impl.getters.ExtractorHelperTest$IqExtractor");
    MapAttributeConfig nameExtractor = new MapAttributeConfig("name", "com.hazelcast.query.impl.getters.ExtractorHelperTest$NameExtractor");
    // WHEN
    Map<String, ValueExtractor> extractors = instantiateExtractors(asList(iqExtractor, nameExtractor));
    // THEN
    assertThat(extractors.get("iq"), instanceOf(IqExtractor.class));
    assertThat(extractors.get("name"), instanceOf(NameExtractor.class));
}
Also used : MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) Test(org.junit.Test)

Example 3 with ValueExtractor

use of com.hazelcast.query.extractor.ValueExtractor in project hazelcast by hazelcast.

the class ExtractorHelperTest method instantiate_extractor.

@Test
public void instantiate_extractor() {
    // GIVEN
    MapAttributeConfig config = new MapAttributeConfig("iq", "com.hazelcast.query.impl.getters.ExtractorHelperTest$IqExtractor");
    // WHEN
    ValueExtractor extractor = instantiateExtractor(config);
    // THEN
    assertThat(extractor, instanceOf(IqExtractor.class));
}
Also used : MapAttributeConfig(com.hazelcast.config.MapAttributeConfig) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) Test(org.junit.Test)

Example 4 with ValueExtractor

use of com.hazelcast.query.extractor.ValueExtractor in project hazelcast by hazelcast.

the class Extractors method instantiateGetter.

private Getter instantiateGetter(InternalSerializationService serializationService, Object targetObject, String attributeName) {
    String attributeNameWithoutArguments = extractAttributeNameNameWithoutArguments(attributeName);
    ValueExtractor valueExtractor = extractors.get(attributeNameWithoutArguments);
    if (valueExtractor != null) {
        Object arguments = argumentsParser.parse(extractArgumentsFromAttributeName(attributeName));
        return new ExtractorGetter(serializationService, valueExtractor, arguments);
    } else {
        if (targetObject instanceof Data) {
            if (genericPortableGetter == null) {
                // will be initialised a couple of times in the worst case
                genericPortableGetter = new PortableGetter(serializationService);
            }
            return genericPortableGetter;
        } else {
            return ReflectionHelper.createGetter(targetObject, attributeName);
        }
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor)

Aggregations

ValueExtractor (com.hazelcast.query.extractor.ValueExtractor)4 MapAttributeConfig (com.hazelcast.config.MapAttributeConfig)3 Test (org.junit.Test)3 Config (com.hazelcast.config.Config)1 Data (com.hazelcast.nio.serialization.Data)1