001/*
002 * (C) Copyright 2006-2012 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Arnaud Kervern <akervern@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.directory.sql.filter;
019
020import org.nuxeo.ecm.core.storage.sql.jdbc.db.Column;
021import org.nuxeo.ecm.directory.DirectoryException;
022
023import java.sql.PreparedStatement;
024import java.sql.SQLException;
025import java.util.Calendar;
026
027/**
028 * Make a BETWEEN SQL predicate
029 *
030 * @since 5.7
031 */
032public class SQLBetweenFilter extends SQLComplexFilter {
033
034    private Calendar from;
035
036    private Calendar to;
037
038    public SQLBetweenFilter(Calendar from, Calendar to) {
039        super("BETWEEN");
040        this.from = from;
041        this.to = to;
042    }
043
044    @Override
045    public int doSetFieldValue(PreparedStatement ps, int index, Column column) throws SQLException {
046        column.setToPreparedStatement(ps, index, from);
047        column.setToPreparedStatement(ps, index + 1, to);
048        return index + 2;
049    }
050
051    @Override
052    public String getRightSide() {
053        return "? AND ?";
054    }
055}