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);
}
}
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);
}
}
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);
}
}
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();
}
}
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();
}
Aggregations