Search in sources :

Example 6 with TypeConverter

use of com.hazelcast.core.TypeConverter in project hazelcast by hazelcast.

the class BetweenVisitor method findBoundaryOrNull.

private Boundaries findBoundaryOrNull(String attributeName, List<GreaterLessPredicate> predicates, Indexes indexes) {
    GreaterLessPredicate mostRightGreaterOrEquals = null;
    GreaterLessPredicate mostLeftLessThanOrEquals = null;
    Index index = indexes.getIndex(attributeName);
    TypeConverter converter = index.getConverter();
    for (GreaterLessPredicate predicate : predicates) {
        if (predicate.less) {
            if (mostLeftLessThanOrEquals == null || isLessThan(mostLeftLessThanOrEquals, predicate, converter)) {
                mostLeftLessThanOrEquals = predicate;
            }
        } else {
            if (mostRightGreaterOrEquals == null || isGreaterThan(mostRightGreaterOrEquals, predicate, converter)) {
                mostRightGreaterOrEquals = predicate;
            }
        }
    }
    if (mostRightGreaterOrEquals == null || mostLeftLessThanOrEquals == null) {
        return null;
    }
    return new Boundaries(mostRightGreaterOrEquals, mostLeftLessThanOrEquals, converter);
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) Index(com.hazelcast.query.impl.Index)

Example 7 with TypeConverter

use of com.hazelcast.core.TypeConverter in project hazelcast by hazelcast.

the class AbstractIndex method obtainConverter.

private TypeConverter obtainConverter(QueryableEntry entry) {
    if (components.length == 1) {
        return entry.getConverter(components[0]);
    } else {
        CompositeConverter existingConverter = (CompositeConverter) converter;
        TypeConverter[] converters = new TypeConverter[components.length];
        for (int i = 0; i < components.length; ++i) {
            TypeConverter existingComponentConverter = getNonTransientComponentConverter(existingConverter, i);
            if (existingComponentConverter == null) {
                converters[i] = entry.getConverter(components[i]);
                assert converters[i] != null;
            } else {
                // preserve the old one to avoid downgrading
                converters[i] = existingComponentConverter;
            }
        }
        return new CompositeConverter(converters);
    }
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter)

Example 8 with TypeConverter

use of com.hazelcast.core.TypeConverter in project hazelcast by hazelcast.

the class EvaluateVisitor method visit.

@Override
public Predicate visit(InPredicate predicate, Indexes indexes) {
    Index index = indexes.matchIndex(predicate.attributeName, predicate.getClass(), IndexMatchHint.PREFER_UNORDERED, SKIP_PARTITIONS_COUNT_CHECK);
    if (index == null) {
        return predicate;
    }
    TypeConverter converter = index.getConverter();
    if (converter == null) {
        return predicate;
    }
    return new EvaluatePredicate(predicate, index.getName());
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) Index(com.hazelcast.query.impl.Index)

Example 9 with TypeConverter

use of com.hazelcast.core.TypeConverter in project hazelcast by hazelcast.

the class EvaluateVisitor method visit.

@Override
public Predicate visit(EqualPredicate predicate, Indexes indexes) {
    Index index = indexes.matchIndex(predicate.attributeName, predicate.getClass(), IndexMatchHint.PREFER_UNORDERED, SKIP_PARTITIONS_COUNT_CHECK);
    if (index == null) {
        return predicate;
    }
    TypeConverter converter = index.getConverter();
    if (converter == null) {
        return predicate;
    }
    return new EvaluatePredicate(predicate, index.getName());
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) Index(com.hazelcast.query.impl.Index)

Example 10 with TypeConverter

use of com.hazelcast.core.TypeConverter in project hazelcast by hazelcast.

the class DiscoveryServicePropertiesUtil method prepareProperties.

/**
 * Validates, verifies, and maps {@code properties} with the given {@code propertyDefinitions}.
 *
 * @param properties          properties from the Hazelcast node configuration (from the service-discovery section)
 * @param propertyDefinitions property definitions specific for the given
 *                            {@link com.hazelcast.spi.discovery.DiscoveryStrategy}
 * @return mapped properties
 * @throws InvalidConfigurationException if the the required properties are not satisfied or any property is not not
 *                                       applicable to the given definitions
 * @throws ValidationException           if any property is invalid
 */
static Map<String, Comparable> prepareProperties(Map<String, Comparable> properties, Collection<PropertyDefinition> propertyDefinitions) {
    Map<String, Comparable> mappedProperties = createHashMap(propertyDefinitions.size());
    for (PropertyDefinition propertyDefinition : propertyDefinitions) {
        String propertyKey = propertyDefinition.key();
        if (properties.containsKey(propertyKey.replace("-", ""))) {
            properties.put(propertyKey, properties.remove(propertyKey.replace("-", "")));
        }
        if (!properties.containsKey(propertyKey)) {
            if (!propertyDefinition.optional()) {
                throw new InvalidConfigurationException(String.format("Missing property '%s' on discovery strategy", propertyKey));
            }
            continue;
        }
        Comparable value = properties.get(propertyKey);
        TypeConverter typeConverter = propertyDefinition.typeConverter();
        Comparable mappedValue = typeConverter.convert(value);
        ValueValidator validator = propertyDefinition.validator();
        if (validator != null) {
            validator.validate(mappedValue);
        }
        mappedProperties.put(propertyKey, mappedValue);
    }
    verifyNoUnknownProperties(mappedProperties, properties);
    return mappedProperties;
}
Also used : TypeConverter(com.hazelcast.core.TypeConverter) ValueValidator(com.hazelcast.config.properties.ValueValidator) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Aggregations

TypeConverter (com.hazelcast.core.TypeConverter)10 Index (com.hazelcast.query.impl.Index)4 PropertyDefinition (com.hazelcast.config.properties.PropertyDefinition)3 ValueValidator (com.hazelcast.config.properties.ValueValidator)2 HashMap (java.util.HashMap)2 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 SimplePropertyDefinition (com.hazelcast.config.properties.SimplePropertyDefinition)1 HazelcastException (com.hazelcast.core.HazelcastException)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1