Search in sources :

Example 1 with JDODataStoreException

use of javax.jdo.JDODataStoreException in project hive by apache.

the class Hive method getPartition.

/**
   * Returns partition metadata
   *
   * @param tbl
   *          the partition's table
   * @param partSpec
   *          partition keys and values
   * @param forceCreate
   *          if this is true and partition doesn't exist then a partition is
   *          created
   * @param partPath the path where the partition data is located
   * @param inheritTableSpecs whether to copy over the table specs for if/of/serde
   * @param newFiles An optional list of new files that were moved into this partition.  If
   *                 non-null these will be included in the DML event sent to the metastore.
   * @return result partition object or null if there is no partition
   * @throws HiveException
   */
public Partition getPartition(Table tbl, Map<String, String> partSpec, boolean forceCreate, String partPath, boolean inheritTableSpecs, List<Path> newFiles) throws HiveException {
    tbl.validatePartColumnNames(partSpec, true);
    List<String> pvals = new ArrayList<String>();
    for (FieldSchema field : tbl.getPartCols()) {
        String val = partSpec.get(field.getName());
        // enable dynamic partitioning
        if ((val == null && !HiveConf.getBoolVar(conf, HiveConf.ConfVars.DYNAMICPARTITIONING)) || (val != null && val.length() == 0)) {
            throw new HiveException("get partition: Value for key " + field.getName() + " is null or empty");
        } else if (val != null) {
            pvals.add(val);
        }
    }
    org.apache.hadoop.hive.metastore.api.Partition tpart = null;
    try {
        tpart = getMSC().getPartitionWithAuthInfo(tbl.getDbName(), tbl.getTableName(), pvals, getUserName(), getGroupNames());
    } catch (NoSuchObjectException nsoe) {
        // this means no partition exists for the given partition
        // key value pairs - thrift cannot handle null return values, hence
        // getPartition() throws NoSuchObjectException to indicate null partition
        tpart = null;
    } catch (Exception e) {
        LOG.error(StringUtils.stringifyException(e));
        throw new HiveException(e);
    }
    try {
        if (forceCreate) {
            if (tpart == null) {
                LOG.debug("creating partition for table " + tbl.getTableName() + " with partition spec : " + partSpec);
                try {
                    tpart = getMSC().appendPartition(tbl.getDbName(), tbl.getTableName(), pvals);
                } catch (AlreadyExistsException aee) {
                    LOG.debug("Caught already exists exception, trying to alter partition instead");
                    tpart = getMSC().getPartitionWithAuthInfo(tbl.getDbName(), tbl.getTableName(), pvals, getUserName(), getGroupNames());
                    alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath);
                } catch (Exception e) {
                    if (CheckJDOException.isJDODataStoreException(e)) {
                        // Using utility method above, so that JDODataStoreException doesn't
                        // have to be used here. This helps avoid adding jdo dependency for
                        // hcatalog client uses
                        LOG.debug("Caught JDO exception, trying to alter partition instead");
                        tpart = getMSC().getPartitionWithAuthInfo(tbl.getDbName(), tbl.getTableName(), pvals, getUserName(), getGroupNames());
                        if (tpart == null) {
                            // in creating the partition, since the partition still doesn't exist.
                            throw e;
                        }
                        alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath);
                    } else {
                        throw e;
                    }
                }
            } else {
                alterPartitionSpec(tbl, partSpec, tpart, inheritTableSpecs, partPath);
                fireInsertEvent(tbl, partSpec, newFiles);
            }
        }
        if (tpart == null) {
            return null;
        }
    } catch (Exception e) {
        LOG.error(StringUtils.stringifyException(e));
        throw new HiveException(e);
    }
    return new Partition(tbl, tpart);
}
Also used : AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with JDODataStoreException

use of javax.jdo.JDODataStoreException in project motech by motech.

the class ObjectException method getMessageFromCause.

protected static String getMessageFromCause(Throwable cause) {
    String message = "Persistence error";
    if (cause instanceof ConstraintViolationException) {
        Set<ConstraintViolation<?>> violations = ((ConstraintViolationException) cause).getConstraintViolations();
        message = "";
        for (ConstraintViolation violation : violations) {
            message += (String.format("Field %s %s\n", violation.getPropertyPath(), violation.getMessage()));
        }
    } else if (cause instanceof JDODataStoreException) {
        for (Throwable exception : ((JDODataStoreException) cause).getNestedExceptions()) {
            if (exception instanceof SQLIntegrityConstraintViolationException) {
                message = exception.getMessage();
                break;
            }
        }
    }
    return message;
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) ConstraintViolationException(javax.validation.ConstraintViolationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) JDODataStoreException(javax.jdo.JDODataStoreException)

Example 3 with JDODataStoreException

use of javax.jdo.JDODataStoreException in project tests by datanucleus.

the class ReadUncommittedIsolationLevelTest method testReadUncommited.

public void testReadUncommited() {
    if (!pmf.supportedOptions().contains("javax.jdo.option.TransactionIsolationLevel.read-uncommitted")) {
        // Datastore doesn't support this isolation level
        return;
    } else if (vendorID != null && vendorID.equalsIgnoreCase("hsql")) {
        // HSQL 2.x can lock up on this
        return;
    }
    // Add some initial data
    pm = pmf.getPersistenceManager();
    pm.setProperty(PropertyNames.PROPERTY_CACHE_L2_TYPE, "none");
    Transaction tx = pm.currentTransaction();
    Object oid;
    try {
        tx.begin();
        // create sample data
        Office o = new Office(1L, ROOM, "desc");
        o = pm.makePersistent(o);
        oid = pm.getObjectId(o);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    String finalDescription = null;
    PersistenceManager pm1 = pmf.getPersistenceManager();
    PersistenceManager pm2 = pmf.getPersistenceManager();
    Transaction tx1 = pm1.currentTransaction();
    Transaction tx2 = pm2.currentTransaction();
    try {
        pm1.setProperty(PropertyNames.PROPERTY_CACHE_L2_TYPE, "none");
        tx1.setIsolationLevel(Constants.TX_READ_UNCOMMITTED);
        tx1.begin();
        pm2.setProperty(PropertyNames.PROPERTY_CACHE_L2_TYPE, "none");
        tx2.setIsolationLevel(Constants.TX_READ_UNCOMMITTED);
        tx2.begin();
        Office o1 = (Office) pm1.getObjectById(oid);
        LOG.info("within tx1 after modifying:" + o1.asString());
        finalDescription = o1.getDescription() + o1.getRoomName();
        o1.setDescription(finalDescription);
        // send UPDATE to database
        pm1.flush();
        LOG.info("within tx1 after modifying:" + o1.asString());
        Office o2 = (Office) pm2.getObjectById(oid);
        LOG.info("within tx2: " + o2.asString());
        assertEquals("uncommited modification not seen", finalDescription, o2.getDescription());
    } catch (JDODataStoreException e) {
        assertFalse("Should be able to see description " + finalDescription + " but " + e.getMessage(), true);
    } finally {
        tx2.commit();
        pm2.close();
        tx1.commit();
        pm1.close();
        clean(Office.class);
        clean(Department.class);
    }
}
Also used : Office(org.jpox.samples.models.company.Office) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JDODataStoreException(javax.jdo.JDODataStoreException)

Example 4 with JDODataStoreException

use of javax.jdo.JDODataStoreException in project tests by datanucleus.

the class SQLQueryTest method testInvalidQueryAllowedByConfiguration.

/**
 * Test of a query not starting with "SELECT"
 */
public void testInvalidQueryAllowedByConfiguration() throws Exception {
    addClassesToSchema(new Class[] { Person.class, Manager.class, Employee.class, Developer.class });
    // Try a query
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.setProperty(PropertyNames.PROPERTY_QUERY_SQL_ALLOWALL, "true");
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        String sqlText = "EXECUTE SELECT 1 FROM PERSON";
        Query query = pm.newQuery("javax.jdo.query.SQL", sqlText);
        query.execute();
    // expected
    } catch (JDODataStoreException dse) {
    // expected, if query is invalid by database
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) JDODataStoreException(javax.jdo.JDODataStoreException)

Example 5 with JDODataStoreException

use of javax.jdo.JDODataStoreException in project tests by datanucleus.

the class SQLQueryTest method testQueryWithTimeout.

/**
 * Test of a query with a timeout.
 */
public void testQueryWithTimeout() throws Exception {
    // Try a query
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        // TODO Change this to a query that will take a LONG time and check for it
        String sqlText = "SELECT count(*) FROM PERSON";
        Query query = pm.newQuery("javax.jdo.query.SQL", sqlText);
        query.addExtension("org.jpox.query.timeout", "1");
        query.execute();
        tx.commit();
    } catch (JDODataStoreException dse) {
        fail("JDODataStoreException thrown when using query timeout : " + dse.getCause().getMessage());
    } catch (JDOUserException ue) {
    // Do nothing, since this is expected
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) JDOUserException(javax.jdo.JDOUserException) JDODataStoreException(javax.jdo.JDODataStoreException)

Aggregations

JDODataStoreException (javax.jdo.JDODataStoreException)15 PersistenceManager (javax.jdo.PersistenceManager)9 Transaction (javax.jdo.Transaction)8 Query (javax.jdo.Query)7 JDOUserException (javax.jdo.JDOUserException)5 ArrayList (java.util.ArrayList)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 JDOQueryInterruptedException (javax.jdo.JDOQueryInterruptedException)2 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)2 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)2 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)2 TException (org.apache.thrift.TException)2 NucleusException (org.datanucleus.exceptions.NucleusException)2 NoQueryResultsException (org.datanucleus.store.query.NoQueryResultsException)2