Search in sources :

Example 21 with JDOException

use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.

the class JDOPersistenceManagerFactory method initialiseMetaData.

protected void initialiseMetaData(PersistenceUnitMetaData pumd) {
    // Prepare Metadata manager for use
    nucleusContext.getMetaDataManager().setAllowXML(getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_ALLOW_XML));
    nucleusContext.getMetaDataManager().setAllowAnnotations(getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_ALLOW_ANNOTATIONS));
    nucleusContext.getMetaDataManager().setValidate(getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_XML_VALIDATE));
    nucleusContext.getMetaDataManager().setDefaultNullable(getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_DEFAULT_NULLABLE));
    if (pumd != null) {
        // This is done now that all PMF properties are set (including the persistence-unit props)
        try {
            nucleusContext.getMetaDataManager().loadPersistenceUnit(pumd, null);
            // Set validation mode if set on persistence-unit
            if (pumd.getValidationMode() != null) {
                getConfiguration().setProperty(PropertyNames.PROPERTY_VALIDATION_MODE, pumd.getValidationMode());
            }
        } catch (NucleusException ne) {
            throw new JDOException(ne.getMessage(), ne);
        }
    }
    // Turn off loading of metadata from here if required
    boolean allowMetadataLoad = nucleusContext.getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_ALLOW_LOAD_AT_RUNTIME);
    if (!allowMetadataLoad) {
        nucleusContext.getMetaDataManager().setAllowMetaDataLoad(false);
    }
}
Also used : NucleusException(org.datanucleus.exceptions.NucleusException) JDOException(javax.jdo.JDOException)

Example 22 with JDOException

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

the class SchemaChangeLockManager method acquireLock.

@Transactional(propagation = Propagation.MANDATORY)
public void acquireLock(String comment) {
    LOGGER.info("Attempting to acquire lock for: {}", comment);
    final PersistenceManager pm = getPersistenceManager();
    final Boolean originalSerializedRead = pm.currentTransaction().getSerializeRead();
    try {
        pm.currentTransaction().setSerializeRead(true);
        final DateTime waitStartTime = DateUtil.now();
        SchemaChangeLock lock = null;
        while (lock == null && beforeTimeout(waitStartTime)) {
            // we keep retrying until timeout is reached
            try {
                LOGGER.info("Waiting for lock...");
                lock = getLock(pm);
            } catch (JDOException e) {
                LOGGER.debug("Exception thrown while waiting for lock, probably timed out", e);
            }
        }
        if (lock == null) {
            throw new IllegalStateException("Unable to acquire schema change lock for: " + comment);
        }
        lock.setComment(comment);
        lock.setTimestamp(DateUtil.now());
        LOGGER.info("Lock acquired for: {}", comment);
    } finally {
        pm.currentTransaction().setSerializeRead(originalSerializedRead);
    }
}
Also used : PersistenceManager(javax.jdo.PersistenceManager) SchemaChangeLock(org.motechproject.mds.domain.SchemaChangeLock) DateTime(org.joda.time.DateTime) JDOException(javax.jdo.JDOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with JDOException

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

the class ComboboxDataMigrationHelper method migrateDataToMultiSelectTable.

private void migrateDataToMultiSelectTable(String srcTable, String field) throws DataMigrationFailedException {
    String dstTable = srcTable + "_" + field.toUpperCase();
    try {
        LOGGER.info(String.format("Creating table %s if it doesn't exists.", dstTable));
        executeQuery(prepareCreateTableQuery(dstTable, field));
        LOGGER.info(String.format("Clearing table %s.", dstTable));
        executeQuery(prepareClearTableQuery(dstTable));
        LOGGER.info(String.format("Migrating data from table %s to table %s.", srcTable, dstTable));
        executeQuery(prepareMigrationToMultiSelectQuery(srcTable, dstTable, field));
        LOGGER.info(String.format("Dropping column %s in table %s.", field, srcTable));
        executeQuery(prepareDropColumnQuery(srcTable, field));
    } catch (JDOException e) {
        throw new DataMigrationFailedException(String.format("Error migrating single-select data from %s to %s.", srcTable, dstTable), e);
    }
}
Also used : DataMigrationFailedException(org.motechproject.mds.exception.entity.DataMigrationFailedException) JDOException(javax.jdo.JDOException)

Example 24 with JDOException

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

the class ObjectStore method scheduledQueryPoll.

@Override
public ScheduledQueryPollResponse scheduledQueryPoll(ScheduledQueryPollRequest request) throws MetaException {
    ensureScheduledQueriesEnabled();
    boolean commited = false;
    ScheduledQueryPollResponse ret = new ScheduledQueryPollResponse();
    Query q = null;
    try {
        openTransaction();
        q = pm.newQuery(MScheduledQuery.class, "nextExecution <= now && enabled && clusterNamespace == ns && activeExecution == null");
        q.setSerializeRead(true);
        q.declareParameters("java.lang.Integer now, java.lang.String ns");
        q.setOrdering("nextExecution");
        int now = (int) (System.currentTimeMillis() / 1000);
        List<MScheduledQuery> results = (List<MScheduledQuery>) q.execute(now, request.getClusterNamespace());
        if (results == null || results.isEmpty()) {
            return new ScheduledQueryPollResponse();
        }
        MScheduledQuery schq = results.get(0);
        schq.setNextExecution(computeNextExecutionTime(schq.getSchedule()));
        MScheduledExecution execution = new MScheduledExecution();
        execution.setScheduledQuery(schq);
        execution.setState(QueryState.INITED);
        execution.setStartTime(now);
        execution.setLastUpdateTime(now);
        schq.setActiveExecution(execution);
        pm.makePersistent(execution);
        pm.makePersistent(schq);
        ObjectStoreTestHook.onScheduledQueryPoll();
        commited = commitTransaction();
        ret.setScheduleKey(schq.getScheduleKey());
        ret.setQuery("/* schedule: " + schq.getScheduleName() + " */" + schq.getQuery());
        ret.setUser(schq.getUser());
        int executionId = ((IntIdentity) pm.getObjectId(execution)).getKey();
        ret.setExecutionId(executionId);
    } catch (JDOException e) {
        LOG.debug("Caught jdo exception; exclusive", e);
        commited = false;
    } finally {
        rollbackAndCleanup(commited, q);
        return commited ? ret : new ScheduledQueryPollResponse();
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) IntIdentity(javax.jdo.identity.IntIdentity) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) JDOException(javax.jdo.JDOException)

Example 25 with JDOException

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

the class TestRetriesInRetryingHMSHandler method testWrappedMetaExceptionRetry.

/*
   * Test retries when InvocationException wrapped in MetaException wrapped in JDOException
   * is thrown
   */
@Test
public void testWrappedMetaExceptionRetry() throws MetaException {
    IHMSHandler mockBaseHandler = Mockito.mock(IHMSHandler.class);
    Mockito.when(mockBaseHandler.getConf()).thenReturn(conf);
    // JDOException wrapped in MetaException wrapped in InvocationException
    MetaException me = new MetaException("Dummy exception");
    me.initCause(new JDOException());
    InvocationTargetException ex = new InvocationTargetException(me);
    Mockito.doThrow(me).doNothing().when(mockBaseHandler).init();
    RetryingHMSHandler.getProxy(conf, mockBaseHandler, false);
    Mockito.verify(mockBaseHandler, Mockito.times(2)).init();
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) JDOException(javax.jdo.JDOException) Test(org.junit.Test) MetastoreCheckinTest(org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)

Aggregations

JDOException (javax.jdo.JDOException)32 PersistenceManager (javax.jdo.PersistenceManager)14 Transaction (javax.jdo.Transaction)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 Query (javax.jdo.Query)7 Iterator (java.util.Iterator)6 JDOUserException (javax.jdo.JDOUserException)6 NucleusException (org.datanucleus.exceptions.NucleusException)6 JDOUnsupportedOptionException (javax.jdo.JDOUnsupportedOptionException)5 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 JDOFatalUserException (javax.jdo.JDOFatalUserException)4 PersistableExpression (javax.jdo.query.PersistableExpression)4 Collection (java.util.Collection)3 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)3 Person (org.jpox.samples.models.company.Person)3 Method (java.lang.reflect.Method)2 Date (java.sql.Date)2 SQLException (java.sql.SQLException)2