PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorFactory.java

#
Java | 81 lines | 47 code | 12 blank | 22 comment | 15 complexity | 26c9b0384d07e4748f0896dbc4a85f9a MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.ql.processors;
  19. import static org.apache.commons.lang.StringUtils.isBlank;
  20. import java.util.Map;
  21. import java.util.HashMap;
  22. import org.apache.hadoop.hive.ql.Driver;
  23. import org.apache.hadoop.hive.ql.session.SessionState;
  24. import org.apache.hadoop.hive.conf.HiveConf;
  25. /**
  26. * CommandProcessorFactory.
  27. *
  28. */
  29. public final class CommandProcessorFactory {
  30. private CommandProcessorFactory() {
  31. // prevent instantiation
  32. }
  33. static Map<HiveConf, Driver> mapDrivers = new HashMap<HiveConf, Driver>();
  34. public static CommandProcessor get(String cmd) {
  35. return get(cmd, null);
  36. }
  37. public static CommandProcessor get(String cmd, HiveConf conf) {
  38. String cmdl = cmd.toLowerCase();
  39. if ("set".equals(cmdl)) {
  40. return new SetProcessor();
  41. } else if ("dfs".equals(cmdl)) {
  42. SessionState ss = SessionState.get();
  43. return new DfsProcessor(ss.getConf());
  44. } else if ("add".equals(cmdl)) {
  45. return new AddResourceProcessor();
  46. } else if ("delete".equals(cmdl)) {
  47. return new DeleteResourceProcessor();
  48. } else if (!isBlank(cmd)) {
  49. if (conf == null) {
  50. return new Driver();
  51. }
  52. Driver drv = mapDrivers.get(conf);
  53. if (drv == null) {
  54. drv = new Driver();
  55. mapDrivers.put(conf, drv);
  56. }
  57. drv.init();
  58. return drv;
  59. }
  60. return null;
  61. }
  62. public static void clean(HiveConf conf) {
  63. Driver drv = mapDrivers.get(conf);
  64. if (drv != null) {
  65. drv.destroy();
  66. }
  67. mapDrivers.remove(conf);
  68. }
  69. }