001/*
002 * (C) Copyright 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Arnaud Kervern <akervern@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.directory.sql.filter;
021
022import org.nuxeo.ecm.core.storage.sql.jdbc.db.Column;
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 * @deprecated since 10.3, use {@link org.nuxeo.ecm.directory.sql.SQLSession#query(org.nuxeo.ecm.core.query.sql.model.QueryBuilder, boolean)} instead
032 */
033@Deprecated
034public class SQLBetweenFilter extends SQLComplexFilter {
035
036    private static final long serialVersionUID = 1L;
037
038    private Calendar from;
039
040    private Calendar to;
041
042    public SQLBetweenFilter(Calendar from, Calendar to) {
043        super("BETWEEN");
044        this.from = from;
045        this.to = to;
046    }
047
048    @Override
049    public int doSetFieldValue(PreparedStatement ps, int index, Column column) throws SQLException {
050        column.setToPreparedStatement(ps, index, from);
051        column.setToPreparedStatement(ps, index + 1, to);
052        return index + 2;
053    }
054
055    @Override
056    public String getRightSide() {
057        return "? AND ?";
058    }
059}