Skip to content

Commit

Permalink
Merge pull request #523 from rareddy/TEIID-3686
Browse files Browse the repository at this point in the history
TEIID-3686: returning correct response in the cases of delete and upd…
  • Loading branch information
rareddy committed Sep 8, 2015
2 parents 1b56883 + d9fb61d commit 3b653e6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
7 changes: 6 additions & 1 deletion odata/src/main/java/org/teiid/odata/TeiidProducer.java
Expand Up @@ -197,7 +197,8 @@ public void deleteEntity(ODataContext context, String entitySetName, OEntityKey
List<SQLParam> parameters = visitor.getParameters();
UpdateResponse response = this.client.executeUpdate(query, parameters);
if (response.getUpdateCount() == 0) {
LogManager.log(MessageLevel.INFO, LogConstants.CTX_ODATA, null, "no entity to delete in = ", entitySetName, " with key=", entityKey.toString()); //$NON-NLS-1$ //$NON-NLS-2$
LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_ODATA, null, "no entity to delete in = ", entitySetName, " with key=", entityKey.toString()); //$NON-NLS-1$ //$NON-NLS-2$
throw new NotFoundException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16018, entityKey, entitySetName));
} else if (response.getUpdateCount() == 1) {
LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_ODATA, null, "deleted entity = ", entitySetName, " with key=", entityKey.toString()); //$NON-NLS-1$ //$NON-NLS-2$
} else {
Expand All @@ -219,6 +220,10 @@ public void updateEntity(ODataContext context, String entitySetName, OEntity ent
int updateCount = update(entitySetName, entity);
if (updateCount > 0) {
LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_ODATA, null, "updated entity = ", entitySetName, " with key=", entity.getEntityKey().toString()); //$NON-NLS-1$ //$NON-NLS-2$
}
else {
LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_ODATA, null, "no entity to update in = ", entitySetName, " with key=", entity.getEntityKey().toString()); //$NON-NLS-1$ //$NON-NLS-2$
throw new NotFoundException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16018, entity.getEntityKey(), entitySetName));
}
}

Expand Down
46 changes: 44 additions & 2 deletions odata/src/test/java/org/teiid/odata/TestODataIntegration.java
Expand Up @@ -739,12 +739,54 @@ public boolean supportsCompareCriteriaEquals() {
request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x(a='a',b='b')"));
request.body("application/json", "{\"c\":5}");
response = request.put(String.class);
assertEquals(200, response.getStatus());
assertEquals(204, response.getStatus());
} finally {
es.stop();
}
}


@Test public void testUpdates() throws Exception {
EmbeddedServer es = new EmbeddedServer();
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hc.addUpdate("DELETE FROM x WHERE x.a = 'a'", new int[] {0});
hc.addUpdate("UPDATE x SET c = 5 WHERE x.a = 'a'", new int[] {0});
es.addTranslator("x", hc);
es.start(new EmbeddedConfiguration());
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, primary key (a)) options (updatable true);");
mmd.addSourceMapping("x", "x", null);
es.deployVDB("northwind", mmd);

TeiidDriver td = es.getDriver();
Properties props = new Properties();
LocalClient lc = new LocalClient("northwind", 1, props);
lc.setDriver(td);
MockProvider.CLIENT = lc;

ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x(a='a')"));
ClientResponse<String> response = request.delete(String.class);
assertEquals(404, response.getStatus());

//not supported
//request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x(a='a',b='b')/c/$value"));
//request.body("text/plain", "5");
//response = request.put(String.class);

request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x(a='a',b='b')"));
request.body("application/json", "{\"c\":5}");
response = request.put(String.class);
assertEquals(404, response.getStatus());
} finally {
es.stop();
}
}
@Test public void testBatch() throws Exception {
EmbeddedServer es = new EmbeddedServer();
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -45,7 +45,7 @@
<version.connector-api>1.5</version.connector-api>
<version.jta>1.1</version.jta>
<jbossas-test-version>jboss-eap-6.4</jbossas-test-version>
<version.org.jboss.oreva>0.8.7</version.org.jboss.oreva>
<version.org.jboss.oreva>0.8.8</version.org.jboss.oreva>
<jbossas-module-root>modules/system/layers/dv</jbossas-module-root>
<version.com.force.api>22.0.0</version.com.force.api>
<version.nux>1.6</version.nux>
Expand Down

0 comments on commit 3b653e6

Please sign in to comment.