Search in sources :

Example 1 with UniqueKeyTransformation

use of com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation in project hazelcast by hazelcast.

the class IndexUtils method validateAndNormalize.

/**
 * Validate provided index config and normalize it's name and attribute names.
 *
 * @param mapName Name of the map
 * @param config Index config.
 * @return Normalized index config.
 * @throws IllegalArgumentException If index configuration is invalid.
 */
@SuppressWarnings("checkstyle:npathcomplexity")
public static IndexConfig validateAndNormalize(String mapName, IndexConfig config) {
    assert config != null;
    // Validate attributes.
    List<String> originalAttributeNames = config.getAttributes();
    if (originalAttributeNames.isEmpty()) {
        throw new IllegalArgumentException("Index must have at least one attribute: " + config);
    }
    if (originalAttributeNames.size() > MAX_ATTRIBUTES) {
        throw new IllegalArgumentException("Index cannot have more than " + MAX_ATTRIBUTES + " attributes: " + config);
    }
    if (config.getType() == IndexType.BITMAP && originalAttributeNames.size() > 1) {
        throw new IllegalArgumentException("Composite bitmap indexes are not supported: " + config);
    }
    List<String> normalizedAttributeNames = new ArrayList<>(originalAttributeNames.size());
    for (String originalAttributeName : originalAttributeNames) {
        validateAttribute(config, originalAttributeName);
        originalAttributeName = originalAttributeName.trim();
        String normalizedAttributeName = canonicalizeAttribute(originalAttributeName);
        assert !normalizedAttributeName.isEmpty();
        int existingIdx = normalizedAttributeNames.indexOf(normalizedAttributeName);
        if (existingIdx != -1) {
            String duplicateOriginalAttributeName = originalAttributeNames.get(existingIdx);
            if (duplicateOriginalAttributeName.equals(originalAttributeName)) {
                throw new IllegalArgumentException("Duplicate attribute name [attributeName=" + originalAttributeName + ", indexConfig=" + config + ']');
            } else {
                throw new IllegalArgumentException("Duplicate attribute names [" + "attributeName1=" + duplicateOriginalAttributeName + ", attributeName2=" + originalAttributeName + ", indexConfig=" + config + ']');
            }
        }
        normalizedAttributeNames.add(normalizedAttributeName);
    }
    // Construct final index.
    String name = config.getName();
    if (name != null && name.trim().isEmpty()) {
        name = null;
    }
    IndexConfig normalizedConfig = buildNormalizedConfig(mapName, config.getType(), name, normalizedAttributeNames);
    if (config.getType() == IndexType.BITMAP) {
        String uniqueKey = config.getBitmapIndexOptions().getUniqueKey();
        UniqueKeyTransformation uniqueKeyTransformation = config.getBitmapIndexOptions().getUniqueKeyTransformation();
        validateAttribute(uniqueKey);
        uniqueKey = canonicalizeAttribute(uniqueKey);
        normalizedConfig.getBitmapIndexOptions().setUniqueKey(uniqueKey).setUniqueKeyTransformation(uniqueKeyTransformation);
    }
    return normalizedConfig;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)

Example 2 with UniqueKeyTransformation

use of com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation in project hazelcast by hazelcast.

the class IndexUtils method getIndexConfigFromXml.

public static IndexConfig getIndexConfigFromXml(Node indexNode, boolean domLevel3, boolean strict) {
    NamedNodeMap attrs = indexNode.getAttributes();
    String name = getTextContent(attrs.getNamedItem("name"), domLevel3);
    if (name.isEmpty()) {
        name = null;
    }
    String typeStr = getTextContent(attrs.getNamedItem("type"), domLevel3);
    IndexType type = getIndexTypeFromXmlName(typeStr);
    IndexConfig res = new IndexConfig().setName(name).setType(type);
    for (Node attributesNode : childElements(indexNode)) {
        if ("attributes".equals(cleanNodeName(attributesNode))) {
            for (Node attributeNode : childElements(attributesNode)) {
                if ("attribute".equals(cleanNodeName(attributeNode))) {
                    String attribute = getTextContent(attributeNode, domLevel3);
                    res.addAttribute(attribute);
                }
            }
        }
    }
    if (type == IndexType.BITMAP) {
        Node optionsNode = childElementWithName(indexNode, "bitmap-index-options", strict);
        if (optionsNode != null) {
            Node uniqueKeyNode = childElementWithName(optionsNode, "unique-key", strict);
            String uniqueKeyText = getTextContent(uniqueKeyNode, domLevel3);
            String uniqueKey = isNullOrEmpty(uniqueKeyText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY : uniqueKeyText;
            Node uniqueKeyTransformationNode = childElementWithName(optionsNode, "unique-key-transformation", strict);
            String uniqueKeyTransformationText = getTextContent(uniqueKeyTransformationNode, domLevel3);
            UniqueKeyTransformation uniqueKeyTransformation = isNullOrEmpty(uniqueKeyTransformationText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY_TRANSFORMATION : UniqueKeyTransformation.fromName(uniqueKeyTransformationText);
            res.getBitmapIndexOptions().setUniqueKey(uniqueKey);
            res.getBitmapIndexOptions().setUniqueKeyTransformation(uniqueKeyTransformation);
        }
    }
    return res;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IndexConfig(com.hazelcast.config.IndexConfig) Node(org.w3c.dom.Node) IndexType(com.hazelcast.config.IndexType) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)

Example 3 with UniqueKeyTransformation

use of com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation in project hazelcast by hazelcast.

the class IndexUtils method getIndexConfigFromYaml.

public static IndexConfig getIndexConfigFromYaml(Node indexNode, boolean domLevel3, boolean strict) {
    NamedNodeMap attrs = indexNode.getAttributes();
    String name = getTextContent(attrs.getNamedItem("name"), domLevel3);
    if (name.isEmpty()) {
        name = null;
    }
    String typeStr = getTextContent(attrs.getNamedItem("type"), domLevel3);
    if (typeStr.isEmpty()) {
        typeStr = IndexConfig.DEFAULT_TYPE.name();
    }
    IndexType type = getIndexTypeFromXmlName(typeStr);
    IndexConfig res = new IndexConfig().setName(name).setType(type);
    Node attributesNode = attrs.getNamedItem("attributes");
    for (Node attributeNode : childElements(attributesNode)) {
        String attribute = attributeNode.getNodeValue();
        res.addAttribute(attribute);
    }
    if (type == IndexType.BITMAP) {
        Node optionsNode = childElementWithName(indexNode, "bitmap-index-options", strict);
        if (optionsNode != null) {
            Node uniqueKeyNode = childElementWithName(optionsNode, "unique-key", strict);
            String uniqueKeyText = getTextContent(uniqueKeyNode, domLevel3);
            String uniqueKey = isNullOrEmpty(uniqueKeyText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY : uniqueKeyText;
            Node uniqueKeyTransformationNode = childElementWithName(optionsNode, "unique-key-transformation", strict);
            String uniqueKeyTransformationText = getTextContent(uniqueKeyTransformationNode, domLevel3);
            UniqueKeyTransformation uniqueKeyTransformation = isNullOrEmpty(uniqueKeyTransformationText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY_TRANSFORMATION : UniqueKeyTransformation.fromName(uniqueKeyTransformationText);
            res.getBitmapIndexOptions().setUniqueKey(uniqueKey);
            res.getBitmapIndexOptions().setUniqueKeyTransformation(uniqueKeyTransformation);
        }
    }
    return res;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IndexConfig(com.hazelcast.config.IndexConfig) Node(org.w3c.dom.Node) IndexType(com.hazelcast.config.IndexType) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)

Aggregations

UniqueKeyTransformation (com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)3 IndexConfig (com.hazelcast.config.IndexConfig)3 IndexType (com.hazelcast.config.IndexType)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 Node (org.w3c.dom.Node)2 ArrayList (java.util.ArrayList)1