001package com.hfg.sql;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.hfg.util.CompareUtil;
007
008//------------------------------------------------------------------------------
009/**
010 Standard SQL join types.
011 <div>
012 @author J. Alex Taylor, hairyfatguy.com
013 </div>
014 */
015//------------------------------------------------------------------------------
016// com.hfg XML/HTML Coding Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public class SQLJoinType
037{
038   private static List<SQLJoinType> sValues = new ArrayList<>(7);
039
040   public static final SQLJoinType JOIN             = new SQLJoinType("JOIN");
041
042   /**
043    Cartesian product (every possible combination) of rows from TABLE1 and TABLE2.
044    The joined table will contain a row consisting of all columns in TABLE1 followed by
045    all columns in TABLE2. If the tables have N and M rows respectively, the joined table will have N * M rows.
046    */
047   public static final SQLJoinType CROSS_JOIN       = new SQLJoinType("CROSS JOIN");
048   public static final SQLJoinType INNER_JOIN       = new SQLJoinType("INNER JOIN");
049   public static final SQLJoinType LEFT_OUTER_JOIN  = new SQLJoinType("LEFT OUTER JOIN");
050   public static final SQLJoinType RIGHT_OUTER_JOIN = new SQLJoinType("RIGHT OUTER JOIN");
051   public static final SQLJoinType FULL_OUTER_JOIN  = new SQLJoinType("FULL OUTER JOIN");
052   public static final SQLJoinType NATURAL_JOIN     = new SQLJoinType("NATURAL JOIN");
053
054   private String mName;
055
056   //###########################################################################
057   // CONSTRUCTORS
058   //###########################################################################
059
060   //---------------------------------------------------------------------------
061   private SQLJoinType(String inName)
062   {
063      mName = inName;
064      sValues.add(this);
065   }
066
067   //###########################################################################
068   // PUBLIC METHODS
069   //###########################################################################
070
071   //---------------------------------------------------------------------------
072   public SQLJoinType[] values()
073   {
074      return sValues.toArray(new SQLJoinType[1]);
075   }
076
077   //---------------------------------------------------------------------------
078   public SQLJoinType valueOf(String inString)
079   {
080      SQLJoinType requestedValue = null;
081
082      for (SQLJoinType value : sValues)
083      {
084         if (value.name().equalsIgnoreCase(inString))
085         {
086            requestedValue = value;
087            break;
088         }
089      }
090
091      return requestedValue;
092   }
093
094   //---------------------------------------------------------------------------
095   @Override
096   public boolean equals(Object inObj2)
097   {
098      return (inObj2 != null
099            && inObj2 instanceof SQLJoinType
100            && 0 == compareTo(inObj2));
101   }
102
103   //---------------------------------------------------------------------------
104   @Override
105   public int hashCode()
106   {
107      int hashCode = name().hashCode();
108
109      return hashCode;
110   }
111
112   //---------------------------------------------------------------------------
113   public int compareTo(Object inObj2)
114   {
115      int result = -1;
116      if (inObj2 != null)
117      {
118         if (inObj2 instanceof SQLJoinType)
119         {
120            SQLJoinType type2 = (SQLJoinType) inObj2;
121
122            result = CompareUtil.compare(name(), type2.name());
123         }
124      }
125
126      return result;
127   }
128
129   //---------------------------------------------------------------------------
130   @Override
131   public String toString()
132   {
133      return name();
134   }
135
136   //---------------------------------------------------------------------------
137   public String name()
138   {
139      return mName;
140   }
141
142}