Search in sources :

Example 1 with MMasterKey

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.");
    }
}
Also used : MMasterKey(org.apache.hadoop.hive.metastore.model.MMasterKey) IntIdentity(javax.jdo.identity.IntIdentity) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 2 with MMasterKey

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();
        }
    }
}
Also used : MMasterKey(org.apache.hadoop.hive.metastore.model.MMasterKey) Query(javax.jdo.Query) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 3 with MMasterKey

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);
    }
}
Also used : MMasterKey(org.apache.hadoop.hive.metastore.model.MMasterKey) Query(javax.jdo.Query) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 4 with MMasterKey

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;
}
Also used : MMasterKey(org.apache.hadoop.hive.metastore.model.MMasterKey) Query(javax.jdo.Query)

Aggregations

MMasterKey (org.apache.hadoop.hive.metastore.model.MMasterKey)4 Query (javax.jdo.Query)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 IntIdentity (javax.jdo.identity.IntIdentity)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)1