Search in sources :

Example 1 with JDOUnsupportedOptionException

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);
            }
        }
    }
}
Also used : TransactionIsolationNotSupportedException(org.datanucleus.exceptions.TransactionIsolationNotSupportedException) JDOImplHelper(javax.jdo.spi.JDOImplHelper) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) Method(java.lang.reflect.Method) NucleusException(org.datanucleus.exceptions.NucleusException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) JDOException(javax.jdo.JDOException) JDOUserException(javax.jdo.JDOUserException) InvalidObjectException(java.io.InvalidObjectException) JDOFatalUserException(javax.jdo.JDOFatalUserException) NucleusException(org.datanucleus.exceptions.NucleusException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TransactionIsolationNotSupportedException(org.datanucleus.exceptions.TransactionIsolationNotSupportedException) TransactionActiveOnCloseException(org.datanucleus.exceptions.TransactionActiveOnCloseException) IOException(java.io.IOException) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) JDOException(javax.jdo.JDOException)

Example 2 with JDOUnsupportedOptionException

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);
}
Also used : JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)

Example 3 with JDOUnsupportedOptionException

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");
}
Also used : JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException)

Example 4 with JDOUnsupportedOptionException

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();
    }
}
Also used : Query(org.datanucleus.store.query.Query) JDOQLTypedQuery(javax.jdo.JDOQLTypedQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) NucleusException(org.datanucleus.exceptions.NucleusException) JDOException(javax.jdo.JDOException)

Example 5 with 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();
    }
}
Also used : Query(org.datanucleus.store.query.Query) JDOQLTypedQuery(javax.jdo.JDOQLTypedQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) JDOUnsupportedOptionException(javax.jdo.JDOUnsupportedOptionException) NucleusException(org.datanucleus.exceptions.NucleusException) JDOException(javax.jdo.JDOException)

Aggregations

JDOUnsupportedOptionException (javax.jdo.JDOUnsupportedOptionException)5 JDOException (javax.jdo.JDOException)3 NucleusException (org.datanucleus.exceptions.NucleusException)3 JDOQLTypedQuery (javax.jdo.JDOQLTypedQuery)2 JDOQuery (org.datanucleus.api.jdo.JDOQuery)2 Query (org.datanucleus.store.query.Query)2 IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JDOFatalUserException (javax.jdo.JDOFatalUserException)1 JDOUserException (javax.jdo.JDOUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)1 JDOImplHelper (javax.jdo.spi.JDOImplHelper)1 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)1 ClassNotResolvedException (org.datanucleus.exceptions.ClassNotResolvedException)1