use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestMatchCriteria method example.
public static MatchCriteria example(String str, char escapeChar) {
MatchCriteria crit = new MatchCriteria();
// $NON-NLS-1$
crit.setLeftExpression(new ElementSymbol("m.g1.e1"));
crit.setRightExpression(new Constant(str));
crit.setEscapeChar(escapeChar);
return crit;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestASTQueries method sampleQuery.
private Query sampleQuery() {
List<ElementSymbol> symbols = new ArrayList<ElementSymbol>();
// $NON-NLS-1$
symbols.add(new ElementSymbol("e1"));
// $NON-NLS-1$
symbols.add(new ElementSymbol("e2"));
Select select = new Select(symbols);
From from = new From();
// $NON-NLS-1$
from.addGroup(new GroupSymbol("G1"));
Query query = new Query();
query.setSelect(select);
query.setFrom(from);
return query;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class Request method validateAccess.
protected boolean validateAccess(String[] commandStr, Command command, CommandType type) throws QueryValidatorException, TeiidComponentException {
boolean returnsResultSet = command.returnsResultSet();
this.returnsUpdateCount = !(command instanceof StoredProcedure) && !returnsResultSet;
if ((this.requestMsg.getResultsMode() == ResultsMode.UPDATECOUNT && returnsResultSet) || (this.requestMsg.getResultsMode() == ResultsMode.RESULTSET && !returnsResultSet)) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new QueryValidatorException(QueryPlugin.Event.TEIID30490, QueryPlugin.Util.getString(this.requestMsg.getResultsMode() == ResultsMode.RESULTSET ? "Request.no_result_set" : "Request.result_set"));
}
createCommandContext();
if (this.requestMsg.isReturnAutoGeneratedKeys() && command instanceof Insert) {
Insert insert = (Insert) command;
List<ElementSymbol> variables = ResolverUtil.resolveElementsInGroup(insert.getGroup(), metadata);
variables.removeAll(insert.getVariables());
Object pk = metadata.getPrimaryKey(insert.getGroup().getMetadataID());
if (pk != null) {
List<?> cols = metadata.getElementIDsInKey(pk);
int colCount = 0;
for (Iterator<ElementSymbol> iter = variables.iterator(); iter.hasNext(); ) {
ElementSymbol variable = iter.next();
if (!(metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.NULL) || metadata.elementSupports(variable.getMetadataID(), SupportConstants.Element.AUTO_INCREMENT)) || !cols.contains(variable.getMetadataID())) {
iter.remove();
}
colCount++;
}
if (colCount == cols.size()) {
context.setReturnAutoGeneratedKeys(variables);
}
}
}
if (!this.workContext.isAdmin() && this.authorizationValidator != null) {
return this.authorizationValidator.validate(commandStr, command, metadata, context, type);
}
return false;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class RequestWorkItem method handleGeneratedKeys.
private boolean handleGeneratedKeys(ResultsMessage response) throws QueryMetadataException, TeiidComponentException {
GeneratedKeysImpl keys = this.processor.getContext().getGeneratedKeys();
if (keys.getKeys().isEmpty()) {
return false;
}
List<ElementSymbol> keyCols = this.processor.getContext().getReturnAutoGeneratedKeys();
// match the key cols with the result
ElementSymbol col = keyCols.get(0);
String[] columnNames = keys.getColumnNames();
if (keyCols.size() != columnNames.length) {
return false;
}
if (!col.getGroupSymbol().isTempTable() && this.processor.getContext().getMetadata().isVirtualGroup(col.getGroupSymbol().getMetadataID())) {
if (keyCols.size() != 1 && ((Insert) originalCommand).getUpdateInfo().isInherentInsert()) {
// TODO: we need to ensure the column names line up correctly
return false;
}
columnNames = new String[columnNames.length];
columnNames[0] = col.getShortName();
}
response.setColumnNames(columnNames);
String[] dataTypes = new String[columnNames.length];
for (int i = 0; i < dataTypes.length; i++) {
dataTypes[i] = DataTypeManager.getDataTypeName(keys.getColumnTypes()[i]);
}
response.setUpdateCount((Integer) response.getResultsList().get(0).get(0));
response.setDataTypes(dataTypes);
response.setResults(keys.getKeys());
response.setLastRow(keys.getKeys().size());
return true;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class DataTierManagerImpl method getColumns.
private List<ElementSymbol> getColumns(TransformationMetadata tm, String name) {
GroupSymbol gs = new GroupSymbol(name);
try {
ResolverUtil.resolveGroup(gs, tm);
List<ElementSymbol> columns = ResolverUtil.resolveElementsInGroup(gs, tm);
return columns;
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
Aggregations