use of javax.jdo.JDOUnsupportedOptionException in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method freezeConfiguration.
/**
* Freezes the current configuration.
* @throws JDOException if the configuration was invalid or inconsistent in some way
*/
protected void freezeConfiguration() {
if (isConfigurable()) {
// Check for invalid javax.jdo properties by calling JDOImplHelper method (new in JDO3.1+)
Method m = null;
try {
m = JDOImplHelper.class.getDeclaredMethod("assertOnlyKnownStandardProperties", new Class[] { Map.class });
m.invoke(null, nucleusContext.getConfiguration().getPersistenceProperties());
} catch (InvocationTargetException ite) {
if (ite.getCause() instanceof JDOException) {
throw (JDOException) ite.getCause();
}
} catch (JDOException jdoe) {
throw jdoe;
} catch (Exception e) {
// Method not present so continue
}
synchronized (this) {
try {
// Initialise the NucleusContext
nucleusContext.initialise();
// Set up the Level 2 Cache
datastoreCache = new JDODataStoreCache(nucleusContext.getLevel2Cache());
setIsNotConfigurable();
} catch (TransactionIsolationNotSupportedException inse) {
throw new JDOUnsupportedOptionException(inse.getMessage());
} catch (NucleusException ne) {
throw NucleusJDOHelper.getJDOExceptionForNucleusException(ne);
}
}
}
}
use of javax.jdo.JDOUnsupportedOptionException in project datanucleus-api-jdo by datanucleus.
the class JDOTransaction method setIsolationLevel.
/**
* Mutator for the isolation level.
* @param level The level
* @throws JDOUserException if the required level is not supported.
*/
public void setIsolationLevel(String level) {
assertNotCommitting();
if (tx.isActive() && !tx.getOptimistic()) {
throw new JDOUnsupportedOptionException("Cannot change the transaction isolation level while a datastore transaction is active");
}
PersistenceManagerFactory pmf = pm.getPersistenceManagerFactory();
if (!pmf.supportedOptions().contains("javax.jdo.option.TransactionIsolationLevel." + level)) {
throw new JDOUnsupportedOptionException("Isolation level \"" + level + "\" not supported by this datastore");
}
int isolationLevel = TransactionUtils.getTransactionIsolationLevelForName(level);
tx.setOption(org.datanucleus.Transaction.TRANSACTION_ISOLATION_OPTION, isolationLevel);
}
use of javax.jdo.JDOUnsupportedOptionException in project tests by datanucleus.
the class PersistenceManagerTest method testProperties.
/**
* Test specification of properties on the PM.
*/
public void testProperties() throws Exception {
PersistenceManager pm = pmf.getPersistenceManager();
Set<String> pmSupportedProps = pm.getSupportedProperties();
assertTrue(pmSupportedProps.contains("javax.jdo.option.DetachAllOnCommit"));
assertTrue(pmSupportedProps.contains("javax.jdo.option.CopyOnAttach"));
assertTrue(pmSupportedProps.contains("javax.jdo.option.DatastoreWriteTimeoutMillis"));
assertTrue(pmSupportedProps.contains("javax.jdo.option.DatastoreReadTimeoutMillis"));
assertTrue(pmSupportedProps.contains("javax.jdo.option.Multithreaded"));
assertTrue(pmSupportedProps.contains("javax.jdo.option.IgnoreCache"));
Map<String, Object> pmProps = pm.getProperties();
assertTrue(pmProps.containsKey("javax.jdo.option.DetachAllOnCommit"));
assertTrue(pmProps.containsKey("javax.jdo.option.CopyOnAttach"));
assertTrue(pmProps.containsKey("javax.jdo.option.DatastoreWriteTimeoutMillis"));
assertTrue(pmProps.containsKey("javax.jdo.option.DatastoreReadTimeoutMillis"));
assertTrue(pmProps.containsKey("javax.jdo.option.Multithreaded"));
assertTrue(pmProps.containsKey("javax.jdo.option.IgnoreCache"));
assertEquals(pmProps.get("javax.jdo.option.DetachAllOnCommit"), false);
assertEquals(pmProps.get("javax.jdo.option.DatastoreReadTimeoutMillis"), 0);
pm.setDetachAllOnCommit(true);
boolean readTimeoutSupported = true;
try {
pm.setDatastoreReadTimeoutMillis(100);
} catch (JDOUnsupportedOptionException uoe) {
readTimeoutSupported = false;
}
pmProps = pm.getProperties();
assertTrue(pmProps.containsKey("javax.jdo.option.DetachAllOnCommit"));
assertTrue(pmProps.containsKey("javax.jdo.option.CopyOnAttach"));
assertTrue(pmProps.containsKey("javax.jdo.option.DatastoreWriteTimeoutMillis"));
assertTrue(pmProps.containsKey("javax.jdo.option.DatastoreReadTimeoutMillis"));
assertTrue(pmProps.containsKey("javax.jdo.option.Multithreaded"));
assertTrue(pmProps.containsKey("javax.jdo.option.IgnoreCache"));
assertEquals(pmProps.get("javax.jdo.option.DetachAllOnCommit"), true);
if (readTimeoutSupported) {
assertEquals(pmProps.get("javax.jdo.option.DatastoreReadTimeoutMillis"), 100);
}
// Check setting of invalid property (this will log a warning currently)
pm.setProperty("myproperty", "someValue");
}
use of javax.jdo.JDOUnsupportedOptionException in project datanucleus-api-jdo by datanucleus.
the class JDOQLTypedQueryImpl method cancel.
/* (non-Javadoc)
* @see javax.jdo.JDOQLTypedQuery#cancel(java.lang.Thread)
*/
@Override
public void cancel(Thread thread) {
assertIsOpen();
if (internalQueries == null || internalQueries.isEmpty()) {
return;
}
try {
Iterator<Query> iter = internalQueries.iterator();
while (iter.hasNext()) {
Query query = iter.next();
query.cancel(thread);
}
} catch (NucleusException ne) {
throw new JDOException("Error in calling Query.cancelAll. See the nested exception", ne);
} catch (UnsupportedOperationException uoe) {
throw new JDOUnsupportedOptionException();
}
}
use of javax.jdo.JDOUnsupportedOptionException in project datanucleus-api-jdo by datanucleus.
the class JDOQLTypedQueryImpl method cancelAll.
/* (non-Javadoc)
* @see javax.jdo.JDOQLTypedQuery#cancelAll()
*/
@Override
public void cancelAll() {
assertIsOpen();
if (internalQueries == null || internalQueries.isEmpty()) {
return;
}
try {
Iterator<Query> iter = internalQueries.iterator();
while (iter.hasNext()) {
Query query = iter.next();
query.cancel();
}
} catch (NucleusException ne) {
throw new JDOException("Error in calling Query.cancelAll. See the nested exception", ne);
} catch (UnsupportedOperationException uoe) {
throw new JDOUnsupportedOptionException();
}
}
Aggregations