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

org.jboss.seam.persistence.QueryParser Maven / Gradle / Ivy

There is a newer version: 3.2.26.ayg
Show newest version
package org.jboss.seam.persistence;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.jboss.seam.core.Expressions.ValueExpression;

import org.jboss.seam.core.Expressions;

public class QueryParser {
	private List> parameterValueBindings = new ArrayList>();
	private StringBuilder ejbqlBuilder;

	public static String getParameterName(int loc) {
		return "el" + (loc + 1);
	}

	public String getEjbql() {
		return ejbqlBuilder.toString();
	}

	public List> getParameterValueBindings() {
		return parameterValueBindings;
	}

	public QueryParser(String ejbql) {
		this(ejbql, 0);
	}

	public QueryParser(String ejbql, int startingParameterNumber) {
		StringTokenizer tokens = new StringTokenizer(ejbql, "#}", true);
		ejbqlBuilder = new StringBuilder(ejbql.length());
		while (tokens.hasMoreTokens()) {
			String token = tokens.nextToken();
			if ("#".equals(token) && tokens.hasMoreTokens()) {
				String expressionToken = tokens.nextToken();

				if (!expressionToken.startsWith("{") || !tokens.hasMoreTokens()) {
					ejbqlBuilder.append(token).append(expressionToken);
				} else {
					String expression = token + expressionToken + tokens.nextToken();
					ejbqlBuilder.append(':').append(getParameterName(startingParameterNumber + parameterValueBindings.size()));
					parameterValueBindings.add(Expressions.instance().createValueExpression(expression));
				}
			} else {
				ejbqlBuilder.append(token);
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy