use of org.apache.hadoop.hive.metastore.model.MMasterKey in project hive by apache.
the class ObjectStore method addMasterKey.
@Override
public int addMasterKey(String key) throws MetaException {
LOG.debug("Begin executing addMasterKey");
boolean committed = false;
MMasterKey masterKey = new MMasterKey(key);
try {
openTransaction();
pm.makePersistent(masterKey);
committed = commitTransaction();
} finally {
if (!committed) {
rollbackTransaction();
}
}
LOG.debug("Done executing addMasterKey with status : " + committed);
if (committed) {
return ((IntIdentity) pm.getObjectId(masterKey)).getKey();
} else {
throw new MetaException("Failed to add master key.");
}
}
use of org.apache.hadoop.hive.metastore.model.MMasterKey in project hive by apache.
the class ObjectStore method getMasterKeys.
@Override
public String[] getMasterKeys() {
LOG.debug("Begin executing getMasterKeys");
boolean committed = false;
Query query = null;
List<MMasterKey> keys;
try {
openTransaction();
query = pm.newQuery(MMasterKey.class);
keys = (List<MMasterKey>) query.execute();
pm.retrieveAll(keys);
committed = commitTransaction();
String[] masterKeys = new String[keys.size()];
for (int i = 0; i < keys.size(); i++) {
masterKeys[i] = keys.get(i).getMasterKey();
}
return masterKeys;
} finally {
LOG.debug("Done executing getMasterKeys with status : " + committed);
if (!committed) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
}
use of org.apache.hadoop.hive.metastore.model.MMasterKey in project hive by apache.
the class ObjectStore method updateMasterKey.
@Override
public void updateMasterKey(Integer id, String key) throws NoSuchObjectException, MetaException {
LOG.debug("Begin executing updateMasterKey");
boolean committed = false;
Query query = null;
MMasterKey masterKey;
try {
openTransaction();
query = pm.newQuery(MMasterKey.class, "keyId == id");
query.declareParameters("java.lang.Integer id");
query.setUnique(true);
masterKey = (MMasterKey) query.execute(id);
if (null != masterKey) {
masterKey.setMasterKey(key);
}
committed = commitTransaction();
} finally {
if (!committed) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
LOG.debug("Done executing updateMasterKey with status : " + committed);
if (null == masterKey) {
throw new NoSuchObjectException("No key found with keyId: " + id);
}
if (!committed) {
throw new MetaException("Though key is found, failed to update it. " + id);
}
}
use of org.apache.hadoop.hive.metastore.model.MMasterKey in project hive by apache.
the class ObjectStore method removeMasterKey.
@Override
public boolean removeMasterKey(Integer id) {
LOG.debug("Begin executing removeMasterKey");
boolean success = false;
Query query = null;
MMasterKey masterKey;
try {
openTransaction();
query = pm.newQuery(MMasterKey.class, "keyId == id");
query.declareParameters("java.lang.Integer id");
query.setUnique(true);
masterKey = (MMasterKey) query.execute(id);
if (null != masterKey) {
pm.deletePersistent(masterKey);
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
LOG.debug("Done executing removeMasterKey with status : " + success);
return (null != masterKey) && success;
}
Aggregations