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

nl.topicus.jdbc.statement.DMLWhereClauseVisitor Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
package nl.topicus.jdbc.statement;

import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.DateValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.DoubleValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.Expression;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.HexValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.JdbcParameter;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.LongValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.StringValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.TimeValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.TimestampValue;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.schema.Column;

abstract class DMLWhereClauseVisitor extends DMLWhereClauseVisitorAdapter
{
	private Column col;

	private ParameterStore parameterStore;

	/**
	 * Only allow equals nl.topicus.jdbc.shaded.com.arisons
	 */
	private boolean foundEquals = false;

	DMLWhereClauseVisitor(ParameterStore parameterStore)
	{
		this.parameterStore = parameterStore;
	}

	protected ParameterStore getParameterStore()
	{
		return parameterStore;
	}

	@Override
	public void visit(Column column)
	{
		// Ideally we should check here whether this column is actually part of
		// the primary key, but that would involve another roundtrip to the
		// database.
		this.col = column;
	}

	protected abstract void visitExpression(Column col, Expression expression);

	@Override
	public void visit(EqualsTo expr)
	{
		// If it is an NOT ID=1, then it's not a valid equals clause
		foundEquals = !expr.isNot();
		super.visit(expr);
	}

	@Override
	public void visit(JdbcParameter parameter)
	{
		visitExpression(col, parameter);
	}

	@Override
	public void visit(DoubleValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(LongValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(DateValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(TimeValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(TimestampValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(StringValue value)
	{
		visitExpression(col, value);
	}

	@Override
	public void visit(HexValue value)
	{
		visitExpression(col, value);
	}

	public boolean isValid()
	{
		return foundEquals && !isInvalid();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy