001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.sql.exp.op; 020 021import lucee.runtime.sql.exp.Expression; 022import lucee.runtime.sql.exp.ExpressionSupport; 023 024public class Operation2 extends ExpressionSupport implements Operation { 025 026 private Expression left; 027 private Expression right; 028 private int operator; 029 030 031 public Operation2(Expression left, Expression right,int operator) { 032 this.left=left; 033 this.right=right; 034 this.operator=operator; 035 } 036 037 038 public static String toString(int operator) { 039 switch(operator) { 040 case Operation.OPERATION2_DIVIDE: return "/"; 041 case Operation.OPERATION2_MINUS: return "-"; 042 case Operation.OPERATION2_MULTIPLY: return "*"; 043 case Operation.OPERATION2_PLUS: return "+"; 044 case Operation.OPERATION2_EXP: return "^"; 045 case Operation.OPERATION2_MOD: return "%"; 046 047 case Operation.OPERATION2_AND: return "and"; 048 case Operation.OPERATION2_OR: return "or"; 049 case Operation.OPERATION2_XOR: return "xor"; 050 051 case Operation.OPERATION2_EQ: return "="; 052 case Operation.OPERATION2_GT: return ">"; 053 case Operation.OPERATION2_GTE: return "=>"; 054 case Operation.OPERATION2_LT: return "<"; 055 case Operation.OPERATION2_LTE: return "<="; 056 case Operation.OPERATION2_LTGT: return "<>"; 057 case Operation.OPERATION2_NEQ: return "!="; 058 case Operation.OPERATION2_NOT_LIKE: return "not like"; 059 case Operation.OPERATION2_LIKE: return "like"; 060 061 case Operation.OPERATION1_PLUS: return "+"; 062 case Operation.OPERATION1_MINUS: return "-"; 063 case Operation.OPERATION1_NOT: return "not"; 064 case Operation.OPERATION1_IS_NOT_NULL: return "is not null"; 065 case Operation.OPERATION1_IS_NULL: return "is null"; 066 } 067 return null; 068 } 069 070 071 public String toString(boolean noAlias) { 072 if(noAlias || getIndex()==0)return left.toString(true)+" "+toString(operator)+" "+right.toString(true); 073 return toString(true)+" as "+getAlias(); 074 } 075 076 077 /** 078 * @return the left 079 */ 080 public Expression getLeft() { 081 return left; 082 } 083 084 085 /** 086 * @return the operator 087 */ 088 public int getOperator() { 089 return operator; 090 } 091 092 093 /** 094 * @return the right 095 */ 096 public Expression getRight() { 097 return right; 098 } 099 100}