use of org.teiid.query.sql.lang.Insert in project teiid by teiid.
the class TestGroupCollectorVisitor method testBatchedUpdateCommand.
public void testBatchedUpdateCommand() {
GroupSymbol g1 = exampleGroupSymbol(1);
GroupSymbol g2 = exampleGroupSymbol(2);
GroupSymbol g3 = exampleGroupSymbol(3);
Insert insert = new Insert();
insert.setGroup(g1);
Update update = new Update();
update.setGroup(g2);
Delete delete = new Delete();
delete.setGroup(g3);
List updates = new ArrayList(3);
updates.add(insert);
updates.add(update);
updates.add(delete);
Set groups = new HashSet();
groups.add(g1);
groups.add(g2);
groups.add(g3);
helpTestGroups(new BatchedUpdateCommand(updates), true, groups);
}
use of org.teiid.query.sql.lang.Insert in project teiid by teiid.
the class TestStaticSymbolMappingVisitor method testVisitInsert2.
public void testVisitInsert2() {
Insert insert = new Insert();
insert.setGroup(exampleGroup(true, 0));
List values = new ArrayList();
// $NON-NLS-1$
values.add(new Constant("abc"));
// $NON-NLS-1$
values.add(new Constant("abc"));
insert.setValues(values);
helpTest(insert, getSymbolMap());
}
use of org.teiid.query.sql.lang.Insert 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.lang.Insert 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.lang.Insert in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public org.teiid.language.Command translate(Command command) {
try {
if (command == null) {
return null;
}
if (command instanceof Query) {
Select result = translate((Query) command);
result.setDependentValues(this.dependentSets);
setProjected(result);
return result;
} else if (command instanceof SetQuery) {
org.teiid.language.SetQuery result = translate((SetQuery) command);
setProjected(result);
return result;
} else if (command instanceof Insert) {
return translate((Insert) command);
} else if (command instanceof Update) {
return translate((Update) command);
} else if (command instanceof Delete) {
return translate((Delete) command);
} else if (command instanceof StoredProcedure) {
return translate((StoredProcedure) command);
} else if (command instanceof BatchedUpdateCommand) {
return translate((BatchedUpdateCommand) command);
}
// $NON-NLS-1$
throw new AssertionError(command.getClass().getName() + " " + command);
} finally {
this.allValues.clear();
this.dependentSets = null;
this.valueIndex = 0;
}
}
Aggregations