View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.jcr.query.qom;
25  
26  import javax.jcr.query.qom.JoinCondition;
27  import org.modeshape.graph.query.model.Join;
28  import org.modeshape.graph.query.model.JoinType;
29  import org.modeshape.jcr.api.query.qom.QueryObjectModelConstants;
30  
31  /**
32   * Implementation of the join for the JCR Query Object Model and the Graph API.
33   */
34  public class JcrJoin extends Join implements javax.jcr.query.qom.Join, JcrSource {
35  
36      private static final long serialVersionUID = 1L;
37  
38      /**
39       * Create a join of the left and right sources, using the supplied join condition. The outputs of the left and right sources
40       * are expected to be equivalent.
41       * 
42       * @param left the left source being joined
43       * @param type the type of join
44       * @param right the right source being joined
45       * @param joinCondition the join condition
46       */
47      public JcrJoin( JcrSource left,
48                      JoinType type,
49                      JcrSource right,
50                      JcrJoinCondition joinCondition ) {
51          super(left, type, right, joinCondition);
52      }
53  
54      /**
55       * {@inheritDoc}
56       * 
57       * @see org.modeshape.graph.query.model.Join#joinCondition()
58       */
59      @Override
60      public JcrJoinCondition joinCondition() {
61          return (JcrJoinCondition)super.joinCondition();
62      }
63  
64      /**
65       * {@inheritDoc}
66       * 
67       * @see org.modeshape.graph.query.model.Join#left()
68       */
69      @Override
70      public JcrSource left() {
71          return (JcrSource)super.left();
72      }
73  
74      /**
75       * {@inheritDoc}
76       * 
77       * @see org.modeshape.graph.query.model.Join#right()
78       */
79      @Override
80      public JcrSource right() {
81          return (JcrSource)super.right();
82      }
83  
84      /**
85       * {@inheritDoc}
86       * 
87       * @see javax.jcr.query.qom.Join#getJoinCondition()
88       */
89      @Override
90      public JoinCondition getJoinCondition() {
91          return joinCondition();
92      }
93  
94      /**
95       * {@inheritDoc}
96       * 
97       * @see javax.jcr.query.qom.Join#getJoinType()
98       */
99      @Override
100     public String getJoinType() {
101         switch (type()) {
102             case CROSS:
103                 return QueryObjectModelConstants.JCR_JOIN_TYPE_CROSS;
104             case INNER:
105                 return QueryObjectModelConstants.JCR_JOIN_TYPE_INNER;
106             case FULL_OUTER:
107                 return QueryObjectModelConstants.JCR_JOIN_TYPE_FULL_OUTER;
108             case LEFT_OUTER:
109                 return QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER;
110             case RIGHT_OUTER:
111                 return QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER;
112         }
113         assert false;
114         return null;
115     }
116 
117     /**
118      * {@inheritDoc}
119      * 
120      * @see javax.jcr.query.qom.Join#getLeft()
121      */
122     @Override
123     public JcrSource getLeft() {
124         return left();
125     }
126 
127     /**
128      * {@inheritDoc}
129      * 
130      * @see javax.jcr.query.qom.Join#getRight()
131      */
132     @Override
133     public JcrSource getRight() {
134         return right();
135     }
136 }