
org.sqlproc.engine.impl.SqlMetaAndOr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql-processor Show documentation
Show all versions of sql-processor Show documentation
SQL Processor - Data Driven Queries
package org.sqlproc.engine.impl;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A META SQL sub-element.
*
*
* Schematically:
*
*
* SqlMetaAndOr
* { SqlMetaIfItem | SqlMetaIfItem...}
* {& SqlMetaIfItem | SqlMetaIfItem...}
* {| SqlMetaIfItem | SqlMetaIfItem...}
*
*
* @author Vladimir Hudec
*/
class SqlMetaAndOr implements SqlMetaElement {
/**
* The internal slf4j logger.
*/
final Logger logger = LoggerFactory.getLogger(getClass());
/**
* The enumeration of types. These types are based on the prefix if this element: {
, {&
* and {|
.
*/
static enum Type {
/**
* The type for the element prefix {
.
*/
NO,
/**
* The type for the element prefix {&
.
*/
AND,
/**
* The type for the element prefix {|
.
*/
OR
};
/**
* The list of sub-elements based on ANTLR grammar.
*/
List elements;
/**
* The type if this element. It controls, how the related ANSI SQL fragment is added to the final ANSI SQL.
*/
Type type = Type.NO;
/**
* Creates a new instance. It's used from inside ANTLR parser.
*
* @param type
* the type, which is used to control, how the related ANSI SQL fragment is added to the final ANSI SQL.
*/
SqlMetaAndOr(Type type) {
this.elements = new ArrayList();
this.type = type;
}
/**
* Adds a new sub-element. It's used from inside ANTLR parser.
*
* @param element
* new sub-element, based on ANTLR grammar
*/
void addElement(SqlMetaIfItem element) {
elements.add(element);
}
/**
* Returns one of the next ANSI SQL fragments:
, AND
or OR
.
*
* @return the ANSI SQL fragment based on the type of this element
*/
String getPrefix() {
String operator = "";
if (type == Type.AND) {
operator = AND_PREFIX;
} else if (type == Type.OR) {
operator = OR_PREFIX;
}
return operator;
}
/**
* {@inheritDoc}
*/
@Override
public SqlProcessResult process(SqlProcessContext ctx) {
SqlProcessResult result = new SqlProcessResult(ctx);
result.addFalse();
StringBuilder s = new StringBuilder(this.getPrefix());
result.setSql(s);
for (SqlMetaIfItem item : this.elements) {
if (!result.isAdd()) {
SqlProcessResult itemResult = item.process(ctx);
if (itemResult.isAdd()) {
s.append(itemResult.getSql());
result.addInputValues(itemResult.getInputValues());
result.addMappedInputValues(itemResult.getMappedInputValues());
result.addOutputValues(itemResult.getOutputValues());
result.addIdentities(itemResult.getIdentities());
result.addOutValues(itemResult.getOutValues());
result.addTrue();
}
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy