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

org.relique.jdbc.csv.ParsedExpression Maven / Gradle / Ivy

The newest version!
/*
 *  CsvJdbc - a JDBC driver for CSV files
 *  Copyright (C) 2008  Mario Frasca
 *
 *  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 library 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 this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.relique.jdbc.csv;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

class ParsedExpression extends LogicalExpression
{
	public Expression content;
	private Map placeholders;
	public ParsedExpression(Expression left)
	{
		content = left;
		placeholders = new HashMap<>();
	}
	@Override
	public boolean isValid()
	{
		return content.isValid();
	}
	@Override
	public Boolean isTrue(Map env) throws SQLException
	{
		if(!placeholders.isEmpty())
		{
			/*
			 * Add prepared statement placeholders to environment.
			 */
			Map useThisEnv = new HashMap<>();
			useThisEnv.putAll(env);
			useThisEnv.putAll(placeholders);
			env = useThisEnv;
		} 
		return ((LogicalExpression)content).isTrue(env);
	}
	@Override
	public Object eval(Map env) throws SQLException
	{
		if(!placeholders.isEmpty())
		{
			/*
			 * Add prepared statement placeholders to environment.
			 */
			Map useThisEnv = new HashMap<>();
			useThisEnv.putAll(env);
			useThisEnv.putAll(placeholders);
			env = useThisEnv;
		} 
		return content.eval(env);
	}
	@Override
	public String toString()
	{
		return content.toString();
	}
	@Override
	public List usedColumns(Set availableColumns)
	{
		return content.usedColumns(availableColumns);
	}
	@Override
	public List aggregateFunctions()
	{
		return content.aggregateFunctions();
	}
	@Override
	public void resetAggregateFunctions()
	{
		content.resetAggregateFunctions();
	}
	public int getPlaceholdersCount()
	{
		return placeholders.size();
	}
	public void setPlaceholdersValues(Object[] values)
	{
		for(int i=1; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy