Search in sources :

Example 1 with Collection

use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.

the class IndexEventHolder method findEvents.

@Override
public Collection<StreamEvent> findEvents(String attribute, Compare.Operator operator, Object value) {
    if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
        StreamEvent resultEvent;
        HashSet<StreamEvent> resultEventSet;
        switch(operator) {
            case LESS_THAN:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values();
            case GREATER_THAN:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values();
            case LESS_THAN_EQUAL:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values();
            case GREATER_THAN_EQUAL:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values();
            case EQUAL:
                resultEventSet = new HashSet<StreamEvent>();
                resultEvent = primaryKeyData.get(value);
                if (resultEvent != null) {
                    resultEventSet.add(resultEvent);
                }
                return resultEventSet;
            case NOT_EQUAL:
                if (primaryKeyData.size() > 0) {
                    resultEventSet = new HashSet<StreamEvent>(primaryKeyData.values());
                } else {
                    return new HashSet<StreamEvent>();
                }
                resultEvent = primaryKeyData.get(value);
                if (resultEvent != null) {
                    resultEventSet.remove(resultEvent);
                }
                return resultEventSet;
        }
    } else {
        HashSet<StreamEvent> resultEventSet = new HashSet<StreamEvent>();
        TreeMap<Object, Set<StreamEvent>> currentIndexedData = indexData.get(attribute);
        Set<StreamEvent> resultEvents;
        switch(operator) {
            case LESS_THAN:
                for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, false).values()) {
                    resultEventSet.addAll(eventSet);
                }
                return resultEventSet;
            case GREATER_THAN:
                for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, false).values()) {
                    resultEventSet.addAll(eventSet);
                }
                return resultEventSet;
            case LESS_THAN_EQUAL:
                for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, true).values()) {
                    resultEventSet.addAll(eventSet);
                }
                return resultEventSet;
            case GREATER_THAN_EQUAL:
                for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, true).values()) {
                    resultEventSet.addAll(eventSet);
                }
                return resultEventSet;
            case EQUAL:
                resultEvents = currentIndexedData.get(value);
                if (resultEvents != null) {
                    resultEventSet.addAll(resultEvents);
                }
                return resultEventSet;
            case NOT_EQUAL:
                if (currentIndexedData.size() > 0) {
                    resultEventSet = new HashSet<StreamEvent>();
                    for (Set<StreamEvent> eventSet : currentIndexedData.values()) {
                        resultEventSet.addAll(eventSet);
                    }
                } else {
                    resultEventSet = new HashSet<StreamEvent>();
                }
                resultEvents = currentIndexedData.get(value);
                if (resultEvents != null) {
                    resultEventSet.removeAll(resultEvents);
                }
                return resultEventSet;
        }
    }
    throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
Also used : OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) Set(java.util.Set) HashSet(java.util.HashSet) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashSet(java.util.HashSet)

Example 2 with Collection

use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.

the class IndexEventHolder method deleteAll.

@Override
public void deleteAll(Collection<StreamEvent> storeEventSet) {
    for (StreamEvent streamEvent : storeEventSet) {
        if (primaryKeyData != null) {
            Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
            StreamEvent deletedEvent = primaryKeyData.remove(primaryKey);
            if (indexData != null) {
                deleteFromIndexes(deletedEvent);
            }
        } else if (indexData != null) {
            deleteFromIndexes(streamEvent);
        }
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 3 with Collection

use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.

the class OperatorParser method constructOperator.

public static Operator constructOperator(Object storeEvents, Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
    if (storeEvents instanceof IndexedEventHolder) {
        CollectionExpression collectionExpression = CollectionExpressionParser.parseCollectionExpression(expression, matchingMetaInfoHolder, (IndexedEventHolder) storeEvents);
        CollectionExecutor collectionExecutor = CollectionExpressionParser.buildCollectionExecutor(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, true, queryName);
        if (collectionExpression instanceof CompareCollectionExpression && ((CompareCollectionExpression) collectionExpression).getOperator() == Compare.Operator.EQUAL && (collectionExpression.getCollectionScope() == INDEXED_RESULT_SET || collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders() != null && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders().length == 1 && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders()[0].getPrimaryKeyAttribute().equals(((AttributeCollectionExpression) ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression()).getAttribute())) {
            return new OverwriteTableIndexOperator(collectionExecutor, queryName);
        } else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression && collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) {
            return new OverwriteTableIndexOperator(collectionExecutor, queryName);
        } else {
            return new IndexOperator(collectionExecutor, queryName);
        }
    } else if (storeEvents instanceof ComplexEventChunk) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new EventChunkOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Map) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new MapOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else if (storeEvents instanceof Collection) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        return new CollectionOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
    } else {
        throw new OperationNotSupportedException(storeEvents.getClass() + " is not supported by OperatorParser!");
    }
}
Also used : OverwriteTableIndexOperator(org.wso2.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) EventChunkOperator(org.wso2.siddhi.core.util.collection.operator.EventChunkOperator) CollectionOperator(org.wso2.siddhi.core.util.collection.operator.CollectionOperator) OverwriteTableIndexOperator(org.wso2.siddhi.core.util.collection.operator.OverwriteTableIndexOperator) IndexOperator(org.wso2.siddhi.core.util.collection.operator.IndexOperator) MapOperator(org.wso2.siddhi.core.util.collection.operator.MapOperator) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) IndexedEventHolder(org.wso2.siddhi.core.table.holder.IndexedEventHolder) CollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CollectionExecutor) Collection(java.util.Collection) CollectionExpression(org.wso2.siddhi.core.util.collection.expression.CollectionExpression) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) Map(java.util.Map)

Example 4 with Collection

use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.

the class AnyAndCollectionExecutor method find.

public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
    Collection<StreamEvent> resultEventSet = findEvents(matchingEvent, indexedEventHolder);
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    if (resultEventSet != null) {
        for (StreamEvent resultEvent : resultEventSet) {
            if (storeEventCloner != null) {
                returnEventChunk.add(storeEventCloner.copyStreamEvent(resultEvent));
            } else {
                returnEventChunk.add(resultEvent);
            }
        }
        return returnEventChunk.getFirst();
    } else {
        return exhaustiveCollectionExecutor.find(matchingEvent, indexedEventHolder, storeEventCloner);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 5 with Collection

use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.

the class ExhaustiveCollectionExecutor method find.

public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
    ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
    Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
    for (StreamEvent storeEvent : storeEvents) {
        matchingEvent.setEvent(storeEventIndex, storeEvent);
        if ((Boolean) expressionExecutor.execute(matchingEvent)) {
            if (storeEventCloner != null) {
                returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
            } else {
                returnEventChunk.add(storeEvent);
            }
        }
        matchingEvent.setEvent(storeEventIndex, null);
    }
    return returnEventChunk.getFirst();
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

Collection (org.wso2.carbon.registry.core.Collection)45 Resource (org.wso2.carbon.registry.core.Resource)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Test (org.junit.Test)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)23 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)20 IOException (java.io.IOException)19 InputStream (java.io.InputStream)19 ArrayList (java.util.ArrayList)17 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)17 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)16 FileInputStream (java.io.FileInputStream)14 OMElement (org.apache.axiom.om.OMElement)13 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 Collection (java.util.Collection)11 CollectionImpl (org.wso2.carbon.registry.core.CollectionImpl)11 ResourceImpl (org.wso2.carbon.registry.core.ResourceImpl)11 File (java.io.File)10