/* * SQLElements object-oriented SQL parsing and generation library * * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber * All Rights Reserved * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html * * $Id: BetweenRange.java 25 2005-12-15 23:36:26Z cgruber $ */ package org.israfil.sqlelements.constraints; import org.israfil.sqlelements.Column; import org.israfil.sqlelements.render.SQLRenderContext; /** * A range comparison constraint. * * @author Christian Edward Gruber * @author Latest: $Author: cgruber $ * @version $Revision: 25 $ */ public class BetweenRange implements ComplexConstraint { private Column operand; private Column begin; private Column end; public BetweenRange(Column operand, Column beginRange, Column endRange) { this.operand = operand; this.begin = beginRange; this.end = endRange; } /** * Renders the BetweenRange. * TODO: Migrate this into SQLRenderContext, as some SQL variants support BETWEEN syntax */ public String render(SQLRenderContext context) { String sql = ""; if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + "."; sql += operand.render(context); sql += " >= "; if (begin.getTable() != null) sql += context.getAlias(begin.getTable()) + "."; sql += begin.render(context); sql += " and "; if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + "."; sql += operand.render(context); sql += " <= "; if (end.getTable() != null) sql += context.getAlias(end.getTable()) + "."; sql += end.render(context); return sql; /* String sql = ""; if (operand.getTable() != null) sql += context.getAlias(operand.getTable()) + "."; sql += operand.render(context); sql += " between "; if (begin.getTable() != null) sql += context.getAlias(begin.getTable()) + "."; sql += begin.render(context); sql += " and "; if (end.getTable() != null) sql += context.getAlias(end.getTable()) + "."; sql += end.render(context); return sql; */ } }