All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jasperreports.engine.query.JRSqlAbstractEqualClause Maven / Gradle / Ivy

The newest version!
/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2023 Cloud Software Group, Inc. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports 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 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see .
 */
package net.sf.jasperreports.engine.query;

import net.sf.jasperreports.engine.JRRuntimeException;


/**
 * Base (NOT) EQUAL clause function for SQL queries.
 * 

* The first token in the $X{...} syntax is the function ID token. Possible values for * the (NOT) EQUAL clause function ID token are: *

    *
  • EQUAL
  • *
  • NOTEQUAL
  • *
*

* * @author Sanda Zaharia ([email protected]) */ public abstract class JRSqlAbstractEqualClause implements JRClauseFunction { public static final String EXCEPTION_MESSAGE_KEY_QUERY_EQUAL_CLAUSE_DB_COLUMN_TOKEN_MISSING = "query.equal.clause.db.column.token.missing"; public static final String EXCEPTION_MESSAGE_KEY_QUERY_EQUAL_CLAUSE_PARAMETER_TOKEN_MISSING = "query.equal.clause.parameter.token.missing"; public static final int POSITION_DB_COLUMN = 1; public static final int POSITION_PARAMETER = 2; protected JRSqlAbstractEqualClause() { } /** * Creates a (NOT) EQUAL SQL clause. * *

* The method expects two clause tokens (after the ID token): *

    *
  • The first token is the SQL column (or column combination) to be used in the clause.
  • *
  • The second token is the name of the report parameter that contains the value to compare to.
  • *
*

*

* The EQUAL function constructs either a column = ? or an * column IS NULL clause, depending on the parameter's value. *

*

* The NOTEQUAL function constructs either a column <> ? or an * column IS NOT NULL clause, depending on the parameter's value. *

*/ @Override public void apply(JRClauseTokens clauseTokens, JRQueryClauseContext queryContext) { String col = clauseTokens.getToken(POSITION_DB_COLUMN); String param = clauseTokens.getToken(POSITION_PARAMETER); if (col == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_QUERY_EQUAL_CLAUSE_DB_COLUMN_TOKEN_MISSING, (Object[])null); } if (param == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_QUERY_EQUAL_CLAUSE_PARAMETER_TOKEN_MISSING, (Object[])null); } StringBuffer sbuffer = queryContext.queryBuffer(); sbuffer.append(col); sbuffer.append(' '); handleEqualOperator(sbuffer, param, queryContext); } /** * Finalizes the query string * * @param sbuffer * @param param * @param queryContext */ protected void finalizeClause(StringBuffer sbuffer, String param, JRQueryClauseContext queryContext) { sbuffer.append(' '); sbuffer.append('?'); queryContext.addQueryParameter(param); } protected abstract void handleEqualOperator(StringBuffer sBuffer, String param, JRQueryClauseContext queryContext); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy