PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/java/server/src/org/openqa/selenium/remote/server/handler/html5/ExecuteSQL.java

https://bitbucket.org/abahdanovich/selenium
Java | 62 lines | 38 code | 9 blank | 15 comment | 0 complexity | ca7e681ef7a0b1bc9ccab7c993aac5f7 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, AGPL-1.0, MIT, Apache-2.0, BSD-3-Clause, GPL-2.0
  1. /*
  2. Copyright 2007-2010 Selenium committers
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package org.openqa.selenium.remote.server.handler.html5;
  14. import com.google.common.collect.Iterables;
  15. import com.google.common.collect.Lists;
  16. import org.openqa.selenium.html5.DatabaseStorage;
  17. import org.openqa.selenium.remote.server.JsonParametersAware;
  18. import org.openqa.selenium.remote.server.Session;
  19. import org.openqa.selenium.remote.server.handler.ResponseAwareWebDriverHandler;
  20. import org.openqa.selenium.remote.server.handler.internal.ArgumentConverter;
  21. import org.openqa.selenium.remote.server.handler.internal.ResultConverter;
  22. import org.openqa.selenium.remote.server.rest.ResultType;
  23. import java.util.List;
  24. import java.util.Map;
  25. public class ExecuteSQL extends ResponseAwareWebDriverHandler implements JsonParametersAware {
  26. private String dbName;
  27. private String query;
  28. private List<Object> args = Lists.newArrayList();
  29. public ExecuteSQL(Session session) {
  30. super(session);
  31. }
  32. public ResultType call() throws Exception {
  33. Object value =
  34. ((DatabaseStorage) getUnwrappedDriver()).executeSQL(dbName, query, args.toArray());
  35. Object result = new ResultConverter(getKnownElements()).apply(value);
  36. response.setValue(result);
  37. return ResultType.SUCCESS;
  38. }
  39. public void setJsonParameters(Map<String, Object> allParameters) throws Exception {
  40. dbName = (String) allParameters.get("dbName");
  41. query = (String) allParameters.get("query");
  42. List<?> params = (List<?>) allParameters.get("args");
  43. args = Lists.newArrayList(Iterables.transform(params,
  44. new ArgumentConverter(getKnownElements())));
  45. }
  46. @Override
  47. public String toString() {
  48. return String.format("[execute SQL query: %s, %s, %s]", dbName, query, args);
  49. }
  50. }