HiveTxnManager txnManager = ctx.getHiveTxnManager();
if (!txnManager.supportsExplicitLock()) {
throw new HiveException(ErrorMsg.LOCK_REQUEST_UNSUPPORTED,
conf.getVar(HiveConf.ConfVars.HIVE_TXN_MANAGER));
}
HiveLockManager lockMgr = txnManager.getLockManager();
if (lockMgr == null) {
throw new HiveException("lock Table LockManager not specified");
}
HiveLockMode mode = HiveLockMode.valueOf(lockTbl.getMode());
String tabName = lockTbl.getTableName();
Table tbl = db.getTable(tabName);
if (tbl == null) {
throw new HiveException("Table " + tabName + " does not exist ");
}
Map<String, String> partSpec = lockTbl.getPartSpec();
HiveLockObjectData lockData =
new HiveLockObjectData(lockTbl.getQueryId(),
String.valueOf(System.currentTimeMillis()),
"EXPLICIT",
lockTbl.getQueryStr());
if (partSpec == null) {
HiveLock lck = lockMgr.lock(new HiveLockObject(tbl, lockData), mode, true);
if (lck == null) {
return 1;
}
return 0;
}
Partition par = db.getPartition(tbl, partSpec, false);
if (par == null) {
throw new HiveException("Partition " + partSpec + " for table " + tabName + " does not exist");
}
HiveLock lck = lockMgr.lock(new HiveLockObject(par, lockData), mode, true);
if (lck == null) {
return 1;
}
return 0;
}