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.graph.query.model; 25 26 import java.util.Collections; 27 import java.util.HashMap; 28 import java.util.Map; 29 import org.modeshape.common.util.CheckArg; 30 31 public enum JoinType implements Readable { 32 INNER("INNER JOIN"), 33 LEFT_OUTER("LEFT OUTER JOIN"), 34 RIGHT_OUTER("RIGHT OUTER JOIN"), 35 FULL_OUTER("FULL OUTER JOIN"), 36 CROSS("CROSS JOIN"); 37 38 private static final Map<String, JoinType> TYPE_BY_SYMBOL; 39 static { 40 Map<String, JoinType> typesBySymbol = new HashMap<String, JoinType>(); 41 for (JoinType type : JoinType.values()) { 42 typesBySymbol.put(type.symbol().toUpperCase(), type); 43 } 44 TYPE_BY_SYMBOL = Collections.unmodifiableMap(typesBySymbol); 45 } 46 47 private final String symbol; 48 49 private JoinType( String symbol ) { 50 this.symbol = symbol; 51 } 52 53 /** 54 * @return symbol 55 */ 56 public String symbol() { 57 return symbol; 58 } 59 60 /** 61 * Check if this join type is an outer join. 62 * 63 * @return true if left/right/full outer, or false otherwise 64 */ 65 public boolean isOuter() { 66 return this.equals(LEFT_OUTER) || this.equals(FULL_OUTER) || this.equals(RIGHT_OUTER); 67 } 68 69 /** 70 * {@inheritDoc} 71 * 72 * @see java.lang.Enum#toString() 73 */ 74 @Override 75 public String toString() { 76 return symbol; 77 } 78 79 /** 80 * Attempt to find the JoinType given a symbol. The matching is done independent of case. 81 * 82 * @param symbol the symbol 83 * @return the JoinType having the supplied symbol, or null if there is no JoinType with the supplied symbol 84 * @throws IllegalArgumentException if the symbol is null 85 */ 86 public static JoinType forSymbol( String symbol ) { 87 CheckArg.isNotNull(symbol, "symbol"); 88 return TYPE_BY_SYMBOL.get(symbol.toUpperCase()); 89 } 90 91 /** 92 * {@inheritDoc} 93 * 94 * @see org.modeshape.graph.query.model.Readable#getString() 95 */ 96 public String getString() { 97 return symbol(); 98 } 99 }