| 1 | /* |
| 2 | * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. |
| 3 | * |
| 4 | * WSO2 Inc. licenses this file to you under the Apache License, |
| 5 | * Version 2.0 (the "License"); you may not use this file except |
| 6 | * in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, |
| 12 | * software distributed under the License is distributed on an |
| 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | * KIND, either express or implied. See the License for the |
| 15 | * specific language governing permissions and limitations |
| 16 | * under the License. |
| 17 | */ |
| 18 | package org.wso2.siddhi.query.api.stream; |
| 19 | |
| 20 | import org.wso2.siddhi.query.api.query.QueryEventStream; |
| 21 | import org.wso2.siddhi.query.api.condition.Condition; |
| 22 | import org.wso2.siddhi.query.api.definition.StreamDefinition; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.List; |
| 26 | import java.util.Map; |
| 27 | |
| 28 | public class JoinStream implements Stream { |
| 29 | |
| 30 | private Stream leftStream; |
| 31 | private Type type; |
| 32 | private Stream rightStream; |
| 33 | private Condition onCompare; |
| 34 | private EventTrigger trigger; |
| 35 | |
| 36 | public enum EventTrigger { |
| 37 | LEFT,RIGHT,ALL |
| 38 | } |
| 39 | public JoinStream(Stream leftStream, Type type, |
| 40 | Stream rightStream, Condition onCompare, EventTrigger trigger) { |
| 41 | this.leftStream = leftStream; |
| 42 | this.type = type; |
| 43 | this.rightStream = rightStream; |
| 44 | this.onCompare = onCompare; |
| 45 | this.trigger = trigger; |
| 46 | } |
| 47 | |
| 48 | public Stream getLeftStream() { |
| 49 | return leftStream; |
| 50 | } |
| 51 | |
| 52 | public Type getType() { |
| 53 | return type; |
| 54 | } |
| 55 | |
| 56 | public Stream getRightStream() { |
| 57 | return rightStream; |
| 58 | } |
| 59 | |
| 60 | public Condition getOnCompare() { |
| 61 | return onCompare; |
| 62 | } |
| 63 | |
| 64 | public EventTrigger getTrigger() { |
| 65 | return trigger; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public List<String> getStreamIds() { |
| 70 | List<String> list = new ArrayList<String>(); |
| 71 | for (String streamId : leftStream.getStreamIds()) { |
| 72 | if (!list.contains(streamId)) { |
| 73 | list.add(streamId); |
| 74 | } |
| 75 | } |
| 76 | for (String streamId : rightStream.getStreamIds()) { |
| 77 | if (!list.contains(streamId)) { |
| 78 | list.add(streamId); |
| 79 | } |
| 80 | } |
| 81 | return list; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public List<QueryEventStream> constructQueryEventStreamList( |
| 86 | Map<String, StreamDefinition> streamDefinitionMap, |
| 87 | List<QueryEventStream> queryEventStreams) { |
| 88 | List<QueryEventStream> queryEventStreamList = leftStream.constructQueryEventStreamList(streamDefinitionMap, queryEventStreams); |
| 89 | return rightStream.constructQueryEventStreamList(streamDefinitionMap, queryEventStreamList); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | public enum Type {JOIN, INNER_JOIN, LEFT_OUTER_JOIN, RIGHT_OUTER_JOIN, FULL_OUTER_JOIN} |
| 94 | } |