PageRenderTime 29ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 2ms 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
 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
19package org.apache.hadoop.hive.ql.processors;
20
21import static org.apache.commons.lang.StringUtils.isBlank;
22import java.util.Map;
23import java.util.HashMap;
24
25import org.apache.hadoop.hive.ql.Driver;
26import org.apache.hadoop.hive.ql.session.SessionState;
27import org.apache.hadoop.hive.conf.HiveConf;
28
29/**
30 * CommandProcessorFactory.
31 *
32 */
33public final class CommandProcessorFactory {
34
35  private CommandProcessorFactory() {
36    // prevent instantiation
37  }
38
39  static Map<HiveConf, Driver> mapDrivers = new HashMap<HiveConf, Driver>();
40  public static CommandProcessor get(String cmd) {
41    return get(cmd, null);
42  }
43
44  public static CommandProcessor get(String cmd, HiveConf conf) {
45    String cmdl = cmd.toLowerCase();
46
47    if ("set".equals(cmdl)) {
48      return new SetProcessor();
49    } else if ("dfs".equals(cmdl)) {
50      SessionState ss = SessionState.get();
51      return new DfsProcessor(ss.getConf());
52    } else if ("add".equals(cmdl)) {
53      return new AddResourceProcessor();
54    } else if ("delete".equals(cmdl)) {
55      return new DeleteResourceProcessor();
56    } else if (!isBlank(cmd)) {
57      if (conf == null) {
58        return new Driver();
59      }
60
61      Driver drv = mapDrivers.get(conf);
62      if (drv == null) {
63        drv = new Driver();
64        mapDrivers.put(conf, drv);
65      }
66      drv.init();
67      return drv;
68    }
69
70    return null;
71  }
72
73  public static void clean(HiveConf conf) {
74    Driver drv = mapDrivers.get(conf);
75    if (drv != null) {
76      drv.destroy();
77    }
78
79    mapDrivers.remove(conf);
80  }
81}