use of org.teiid.query.sql.lang.Update in project teiid by teiid.
the class TestPreparedStatementBatchedUpdate method testBatchedUpdatePushdown.
@Test
public void testBatchedUpdatePushdown() throws Exception {
// Create query
// $NON-NLS-1$
String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?";
// Create a testable prepared plan cache
SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager();
// $NON-NLS-1$
dataManager.addData("UPDATE pm1.g1 SET e1 = ?, e3 = ? WHERE pm1.g1.e2 = ?", new List[] { Arrays.asList(4) });
// Source capabilities must support batched updates
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.BULK_UPDATE, true);
// $NON-NLS-1$
capFinder.addCapabilities("pm1", caps);
// batch with two commands
ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
// $NON-NLS-1$
values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "a", Boolean.FALSE, new Integer(0) })));
values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, Boolean.FALSE, new Integer(1) })));
List<?>[] expected = new List[] { Arrays.asList(4) };
// Create the plan and process the query
TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false, RealMetadataFactory.example1VDB());
Update update = (Update) dataManager.getCommandHistory().iterator().next();
assertTrue(((Constant) update.getChangeList().getClauses().get(0).getValue()).isMultiValued());
}
use of org.teiid.query.sql.lang.Update in project teiid by teiid.
the class TeiidServiceHandler method upsertStreamProperty.
@Override
public void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent, NoContentResponse response) throws ODataLibraryException, ODataApplicationException {
UpdateResponse updateResponse = null;
EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
Update update = visitor.updateStreamProperty(edmProperty, streamContent);
updateResponse = getClient().executeUpdate(update, visitor.getParameters());
} catch (SQLException | TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writeNoContent();
} else {
response.writeNotModified();
}
}
use of org.teiid.query.sql.lang.Update in project teiid by teiid.
the class TeiidServiceHandler method updateProperty.
/**
* since Teiid only deals with primitive types, merge does not apply
*/
@Override
public void updateProperty(DataRequest request, Property property, boolean rawValue, boolean merge, String entityETag, PropertyResponse response) throws ODataLibraryException, ODataApplicationException {
// TODO: need to match entityETag.
checkETag(entityETag);
UpdateResponse updateResponse = null;
EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
Update update = visitor.updateProperty(edmProperty, property, this.prepared, rawValue);
updateResponse = getClient().executeUpdate(update, visitor.getParameters());
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} catch (TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writePropertyUpdated();
} else {
response.writeNotModified();
}
}
use of org.teiid.query.sql.lang.Update in project teiid by teiid.
the class UpdateResolver method resolveProceduralCommand.
/**
* @see org.teiid.query.resolver.ProcedureContainerResolver#resolveProceduralCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter)
*/
public void resolveProceduralCommand(Command command, TempMetadataAdapter metadata) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
// Cast to known type
Update update = (Update) command;
// Resolve elements and functions
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
groups.add(update.getGroup());
for (SetClause clause : update.getChangeList().getClauses()) {
ResolverVisitor.resolveLanguageObject(clause.getSymbol(), groups, null, metadata);
}
QueryResolver.resolveSubqueries(command, metadata, groups);
ResolverVisitor.resolveLanguageObject(update, groups, update.getExternalGroupContexts(), metadata);
}
use of org.teiid.query.sql.lang.Update in project teiid by teiid.
the class TestGroupCollectorVisitor method testUpdate.
public void testUpdate() {
GroupSymbol gs1 = exampleGroupSymbol(1);
Update update = new Update();
update.setGroup(gs1);
Set groups = new HashSet();
groups.add(gs1);
helpTestGroups(update, true, groups);
}
Aggregations