Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  */
0018 package org.apache.hive.service.cli;
0019 
0020 import org.apache.hive.service.rpc.thrift.TOperationHandle;
0021 import org.apache.hive.service.rpc.thrift.TProtocolVersion;
0022 
0023 public class OperationHandle extends Handle {
0024 
0025   private final OperationType opType;
0026   private final TProtocolVersion protocol;
0027   private boolean hasResultSet = false;
0028 
0029   public OperationHandle(OperationType opType, TProtocolVersion protocol) {
0030     super();
0031     this.opType = opType;
0032     this.protocol = protocol;
0033   }
0034 
0035   // dummy handle for ThriftCLIService
0036   public OperationHandle(TOperationHandle tOperationHandle) {
0037     this(tOperationHandle, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1);
0038   }
0039 
0040   public OperationHandle(TOperationHandle tOperationHandle, TProtocolVersion protocol) {
0041     super(tOperationHandle.getOperationId());
0042     this.opType = OperationType.getOperationType(tOperationHandle.getOperationType());
0043     this.hasResultSet = tOperationHandle.isHasResultSet();
0044     this.protocol = protocol;
0045   }
0046 
0047   public OperationType getOperationType() {
0048     return opType;
0049   }
0050 
0051   public void setHasResultSet(boolean hasResultSet) {
0052     this.hasResultSet = hasResultSet;
0053   }
0054 
0055   public boolean hasResultSet() {
0056     return hasResultSet;
0057   }
0058 
0059   public TOperationHandle toTOperationHandle() {
0060     TOperationHandle tOperationHandle = new TOperationHandle();
0061     tOperationHandle.setOperationId(getHandleIdentifier().toTHandleIdentifier());
0062     tOperationHandle.setOperationType(opType.toTOperationType());
0063     tOperationHandle.setHasResultSet(hasResultSet);
0064     return tOperationHandle;
0065   }
0066 
0067   public TProtocolVersion getProtocolVersion() {
0068     return protocol;
0069   }
0070 
0071   @Override
0072   public int hashCode() {
0073     final int prime = 31;
0074     int result = super.hashCode();
0075     result = prime * result + ((opType == null) ? 0 : opType.hashCode());
0076     return result;
0077   }
0078 
0079   @Override
0080   public boolean equals(Object obj) {
0081     if (this == obj) {
0082       return true;
0083     }
0084     if (!super.equals(obj)) {
0085       return false;
0086     }
0087     if (!(obj instanceof OperationHandle)) {
0088       return false;
0089     }
0090     OperationHandle other = (OperationHandle) obj;
0091     if (opType != other.opType) {
0092       return false;
0093     }
0094     return true;
0095   }
0096 
0097   @Override
0098   public String toString() {
0099     return "OperationHandle [opType=" + opType + ", getHandleIdentifier()=" + getHandleIdentifier()
0100         + "]";
0101   }
0102 }