/* * DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2012 ForgeRock Inc. All rights reserved. * * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at * http://forgerock.org/license/CDDLv1.0.html * See the License for the specific language governing * permission and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at http://forgerock.org/license/CDDLv1.0.html * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" */ package org.forgerock.openicf.mssql; import org.identityconnectors.common.StringUtil; import org.identityconnectors.framework.common.objects.AttributeUtil; import org.identityconnectors.framework.common.objects.filter.AbstractFilterTranslator; import org.identityconnectors.framework.common.objects.filter.ContainsFilter; import org.identityconnectors.framework.common.objects.filter.EndsWithFilter; import org.identityconnectors.framework.common.objects.filter.EqualsFilter; import org.identityconnectors.framework.common.objects.filter.GreaterThanFilter; import org.identityconnectors.framework.common.objects.filter.GreaterThanOrEqualFilter; import org.identityconnectors.framework.common.objects.filter.LessThanFilter; import org.identityconnectors.framework.common.objects.filter.LessThanOrEqualFilter; import org.identityconnectors.framework.common.objects.filter.StartsWithFilter; /** * This is an implementation of AbstractFilterTranslator that gives a concrete * representation of which filters can be applied at the connector level * (natively). If the MSSQLServer doesn't support a certain expression type, * that factory method should return null. This level of filtering is present * only to allow any native constructs that may be available to help reduce the * result set for the framework, which will (strictly) reapply all filters * specified after the connector does the initial filtering. * <p> * <p> * Note: The generic query type is most commonly a String, but does not have to * be. * * @author $author$ * @version $Revision$ $Date$ */ public class MSSQLServerFilterTranslator extends AbstractFilterTranslator<String> { /** * {@inheritDoc} */ @Override protected String createContainsExpression(ContainsFilter filter, boolean not) { /* * Example implementation: You may define the format of the queries for * your connector, but you must make sure that the executeQuery() (if * you implemented Search) method handles it appropriately. */ String name = filter.getAttribute().getName(); String value = AttributeUtil.getAsStringValue(filter.getAttribute()); if (StringUtil.isBlank(value)) { return null; } else if (not) { // create an expression that means "not contains" or // "doesn't contain" if possible return name + "!=*" + value + "*"; } else { return name + "=*" + value + "*"; } } /** * {@inheritDoc} */ @Override protected String createEndsWithExpression(EndsWithFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createStartsWithExpression(StartsWithFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createEqualsExpression(EqualsFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createAndExpression(String leftExpression, String rightExpression) { return null; } /** * {@inheritDoc} */ @Override protected String createOrExpression(String leftExpression, String rightExpression) { return null; } /** * {@inheritDoc} */ @Override protected String createGreaterThanExpression(GreaterThanFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createGreaterThanOrEqualExpression(GreaterThanOrEqualFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createLessThanExpression(LessThanFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createLessThanOrEqualExpression(LessThanOrEqualFilter filter, boolean not) { return null; } }