0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 package org.apache.hive.service.cli;
0020
0021 import java.nio.ByteBuffer;
0022 import java.util.UUID;
0023
0024 import org.apache.hive.service.cli.thrift.THandleIdentifier;
0025
0026
0027
0028
0029
0030 public class HandleIdentifier {
0031 private final UUID publicId;
0032 private final UUID secretId;
0033
0034 public HandleIdentifier() {
0035 publicId = UUID.randomUUID();
0036 secretId = UUID.randomUUID();
0037 }
0038
0039 public HandleIdentifier(UUID publicId, UUID secretId) {
0040 this.publicId = publicId;
0041 this.secretId = secretId;
0042 }
0043
0044 public HandleIdentifier(THandleIdentifier tHandleId) {
0045 ByteBuffer bb = ByteBuffer.wrap(tHandleId.getGuid());
0046 this.publicId = new UUID(bb.getLong(), bb.getLong());
0047 bb = ByteBuffer.wrap(tHandleId.getSecret());
0048 this.secretId = new UUID(bb.getLong(), bb.getLong());
0049 }
0050
0051 public UUID getPublicId() {
0052 return publicId;
0053 }
0054
0055 public UUID getSecretId() {
0056 return secretId;
0057 }
0058
0059 public THandleIdentifier toTHandleIdentifier() {
0060 byte[] guid = new byte[16];
0061 byte[] secret = new byte[16];
0062 ByteBuffer guidBB = ByteBuffer.wrap(guid);
0063 ByteBuffer secretBB = ByteBuffer.wrap(secret);
0064 guidBB.putLong(publicId.getMostSignificantBits());
0065 guidBB.putLong(publicId.getLeastSignificantBits());
0066 secretBB.putLong(secretId.getMostSignificantBits());
0067 secretBB.putLong(secretId.getLeastSignificantBits());
0068 return new THandleIdentifier(ByteBuffer.wrap(guid), ByteBuffer.wrap(secret));
0069 }
0070
0071 @Override
0072 public int hashCode() {
0073 final int prime = 31;
0074 int result = 1;
0075 result = prime * result + ((publicId == null) ? 0 : publicId.hashCode());
0076 result = prime * result + ((secretId == null) ? 0 : secretId.hashCode());
0077 return result;
0078 }
0079
0080 @Override
0081 public boolean equals(Object obj) {
0082 if (this == obj) {
0083 return true;
0084 }
0085 if (obj == null) {
0086 return false;
0087 }
0088 if (!(obj instanceof HandleIdentifier)) {
0089 return false;
0090 }
0091 HandleIdentifier other = (HandleIdentifier) obj;
0092 if (publicId == null) {
0093 if (other.publicId != null) {
0094 return false;
0095 }
0096 } else if (!publicId.equals(other.publicId)) {
0097 return false;
0098 }
0099 if (secretId == null) {
0100 if (other.secretId != null) {
0101 return false;
0102 }
0103 } else if (!secretId.equals(other.secretId)) {
0104 return false;
0105 }
0106 return true;
0107 }
0108
0109 @Override
0110 public String toString() {
0111 return publicId.toString();
0112 }
0113 }