Package org.apache.openjpa.persistence.jdbc

Examples of org.apache.openjpa.persistence.jdbc.JDBCFetchPlan


    public void testJdbcFetchDirectionHint() {
        String hintName = "openjpa.jdbc.FetchDirection";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();

        fetchDirectionHintTest(fPlan, fConfig, hintName, String
            .valueOf(ResultSet.FETCH_FORWARD), FetchDirection.FORWARD,
            ResultSet.FETCH_FORWARD);
        fetchDirectionHintTest(fPlan, fConfig, hintName,
            ResultSet.FETCH_FORWARD, FetchDirection.FORWARD,
            ResultSet.FETCH_FORWARD);

        fetchDirectionHintTest(fPlan, fConfig, hintName, String
            .valueOf(ResultSet.FETCH_REVERSE), FetchDirection.REVERSE,
            ResultSet.FETCH_REVERSE);
        fetchDirectionHintTest(fPlan, fConfig, hintName,
            ResultSet.FETCH_REVERSE, FetchDirection.REVERSE,
            ResultSet.FETCH_REVERSE);

        fetchDirectionHintTest(fPlan, fConfig, hintName, String
            .valueOf(ResultSet.FETCH_UNKNOWN), FetchDirection.UNKNOWN,
            ResultSet.FETCH_UNKNOWN);
        fetchDirectionHintTest(fPlan, fConfig, hintName,
            ResultSet.FETCH_UNKNOWN, FetchDirection.UNKNOWN,
            ResultSet.FETCH_UNKNOWN);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, FetchConfiguration.DEFAULT);
            assertEquals(fConfig.getFetchDirection(), ResultSet.FETCH_FORWARD);
        } catch (Exception e) {
            fail("Unexpected " + e.getClass().getName());
        }
        em.close();
View Full Code Here


    public void testFetchPlanIsolationHint() {
        String hintName = "openjpa.FetchPlan.Isolation";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();

        isolationHintTest(oem, fPlan, fConfig, hintName, "default",
            IsolationLevel.DEFAULT, -1);
        isolationHintTest(oem, fPlan, fConfig, hintName, "DEFAULT",
            IsolationLevel.DEFAULT, -1);
        isolationHintTest(oem, fPlan, fConfig, hintName,
            IsolationLevel.DEFAULT, IsolationLevel.DEFAULT, -1);

        boolean supportIsolationForUpdate = ((JDBCConfiguration) fConfig
            .getContext().getConfiguration()).getDBDictionaryInstance()
            .supportsIsolationForUpdate();
        if (supportIsolationForUpdate) {
            isolationHintTest(oem, fPlan, fConfig, hintName, "none",
                IsolationLevel.NONE, Connection.TRANSACTION_NONE);
            isolationHintTest(oem, fPlan, fConfig, hintName, "NONE",
                IsolationLevel.NONE, Connection.TRANSACTION_NONE);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                IsolationLevel.NONE, IsolationLevel.NONE,
                Connection.TRANSACTION_NONE);

            isolationHintTest(oem, fPlan, fConfig, hintName,
                "read-uncommitted", IsolationLevel.READ_UNCOMMITTED,
                Connection.TRANSACTION_READ_UNCOMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                "READ_UNCOMMITTED", IsolationLevel.READ_UNCOMMITTED,
                Connection.TRANSACTION_READ_UNCOMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                IsolationLevel.READ_UNCOMMITTED,
                IsolationLevel.READ_UNCOMMITTED,
                Connection.TRANSACTION_READ_UNCOMMITTED);

            isolationHintTest(oem, fPlan, fConfig, hintName, "read-committed",
                IsolationLevel.READ_COMMITTED,
                Connection.TRANSACTION_READ_COMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName, "READ_COMMITTED",
                IsolationLevel.READ_COMMITTED,
                Connection.TRANSACTION_READ_COMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                IsolationLevel.READ_COMMITTED, IsolationLevel.READ_COMMITTED,
                Connection.TRANSACTION_READ_COMMITTED);

            isolationHintTest(oem, fPlan, fConfig, hintName, "repeatable-read",
                IsolationLevel.REPEATABLE_READ,
                Connection.TRANSACTION_REPEATABLE_READ);
            isolationHintTest(oem, fPlan, fConfig, hintName, "REPEATABLE_READ",
                IsolationLevel.REPEATABLE_READ,
                Connection.TRANSACTION_REPEATABLE_READ);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                IsolationLevel.REPEATABLE_READ, IsolationLevel.REPEATABLE_READ,
                Connection.TRANSACTION_REPEATABLE_READ);

            isolationHintTest(oem, fPlan, fConfig, hintName, "serializable",
                IsolationLevel.SERIALIZABLE,
                Connection.TRANSACTION_SERIALIZABLE);
            isolationHintTest(oem, fPlan, fConfig, hintName, "SERIALIZABLE",
                IsolationLevel.SERIALIZABLE,
                Connection.TRANSACTION_SERIALIZABLE);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                IsolationLevel.SERIALIZABLE, IsolationLevel.SERIALIZABLE,
                Connection.TRANSACTION_SERIALIZABLE);
        }

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
View Full Code Here

    public void testJdbcTransactionIsolationHint() {
        String hintName = "openjpa.jdbc.TransactionIsolation";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();

        isolationHintTest(oem, fPlan, fConfig, hintName, "-1",
            IsolationLevel.DEFAULT, -1);
        isolationHintTest(oem, fPlan, fConfig, hintName, -1,
            IsolationLevel.DEFAULT, -1);

        boolean supportIsolationForUpdate = ((JDBCConfiguration) fConfig
            .getContext().getConfiguration()).getDBDictionaryInstance()
            .supportsIsolationForUpdate();
        if (supportIsolationForUpdate) {
            isolationHintTest(oem, fPlan, fConfig, hintName, String
                .valueOf(Connection.TRANSACTION_NONE), IsolationLevel.NONE,
                Connection.TRANSACTION_NONE);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                Connection.TRANSACTION_NONE, IsolationLevel.NONE,
                Connection.TRANSACTION_NONE);

            isolationHintTest(oem, fPlan, fConfig, hintName, String
                .valueOf(Connection.TRANSACTION_READ_UNCOMMITTED),
                IsolationLevel.READ_UNCOMMITTED,
                Connection.TRANSACTION_READ_UNCOMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                Connection.TRANSACTION_READ_UNCOMMITTED,
                IsolationLevel.READ_UNCOMMITTED,
                Connection.TRANSACTION_READ_UNCOMMITTED);

            isolationHintTest(oem, fPlan, fConfig, hintName, String
                .valueOf(Connection.TRANSACTION_READ_COMMITTED),
                IsolationLevel.READ_COMMITTED,
                Connection.TRANSACTION_READ_COMMITTED);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                Connection.TRANSACTION_READ_COMMITTED,
                IsolationLevel.READ_COMMITTED,
                Connection.TRANSACTION_READ_COMMITTED);

            isolationHintTest(oem, fPlan, fConfig, hintName, String
                .valueOf(Connection.TRANSACTION_REPEATABLE_READ),
                IsolationLevel.REPEATABLE_READ,
                Connection.TRANSACTION_REPEATABLE_READ);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                Connection.TRANSACTION_REPEATABLE_READ,
                IsolationLevel.REPEATABLE_READ,
                Connection.TRANSACTION_REPEATABLE_READ);

            isolationHintTest(oem, fPlan, fConfig, hintName, String
                .valueOf(Connection.TRANSACTION_SERIALIZABLE),
                IsolationLevel.SERIALIZABLE,
                Connection.TRANSACTION_SERIALIZABLE);
            isolationHintTest(oem, fPlan, fConfig, hintName,
                Connection.TRANSACTION_SERIALIZABLE,
                IsolationLevel.SERIALIZABLE,
                Connection.TRANSACTION_SERIALIZABLE);
        }
        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -2);
            fPlan.setHint(hintName, -3);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, FetchConfiguration.DEFAULT);
            assertEquals(IsolationLevel.DEFAULT, fPlan.getIsolation());
            assertEquals(-1, fConfig.getIsolation());
        } catch (Exception e) {
            fail("Unexpected " + e.getClass().getName());
        }
        em.close();
View Full Code Here

    public void testFetchPlanLRSSizeAlgorithmHint() {
        String hintName = "openjpa.FetchPlan.LRSSizeAlgorithm";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();

        lrsSizeHintTest(fPlan, fConfig, hintName, "query",
            LRSSizeAlgorithm.QUERY, LRSSizes.SIZE_QUERY);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.QUERY.name(),
            LRSSizeAlgorithm.QUERY, LRSSizes.SIZE_QUERY);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.QUERY,
            LRSSizeAlgorithm.QUERY, LRSSizes.SIZE_QUERY);

        lrsSizeHintTest(fPlan, fConfig, hintName, "last",
            LRSSizeAlgorithm.LAST, LRSSizes.SIZE_LAST);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.LAST.name(),
            LRSSizeAlgorithm.LAST, LRSSizes.SIZE_LAST);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.LAST,
            LRSSizeAlgorithm.LAST, LRSSizes.SIZE_LAST);

        lrsSizeHintTest(fPlan, fConfig, hintName, "unknown",
            LRSSizeAlgorithm.UNKNOWN, LRSSizes.SIZE_UNKNOWN);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.UNKNOWN
            .name(), LRSSizeAlgorithm.UNKNOWN, LRSSizes.SIZE_UNKNOWN);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizeAlgorithm.UNKNOWN,
            LRSSizeAlgorithm.UNKNOWN, LRSSizes.SIZE_UNKNOWN);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught unexpected exception " + e,
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
View Full Code Here

    public void testFetchPlanLRSSizeHint() {
        String hintName = "openjpa.FetchPlan.LRSSize";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();

        lrsSizeHintTest(fPlan, fConfig, hintName, String
            .valueOf(LRSSizes.SIZE_QUERY), LRSSizeAlgorithm.QUERY,
            LRSSizes.SIZE_QUERY);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizes.SIZE_QUERY,
            LRSSizeAlgorithm.QUERY, LRSSizes.SIZE_QUERY);

        lrsSizeHintTest(fPlan, fConfig, hintName, String
            .valueOf(LRSSizes.SIZE_LAST), LRSSizeAlgorithm.LAST,
            LRSSizes.SIZE_LAST);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizes.SIZE_LAST,
            LRSSizeAlgorithm.LAST, LRSSizes.SIZE_LAST);

        lrsSizeHintTest(fPlan, fConfig, hintName, String
            .valueOf(LRSSizes.SIZE_UNKNOWN), LRSSizeAlgorithm.UNKNOWN,
            LRSSizes.SIZE_UNKNOWN);
        lrsSizeHintTest(fPlan, fConfig, hintName, LRSSizes.SIZE_UNKNOWN,
            LRSSizeAlgorithm.UNKNOWN, LRSSizes.SIZE_UNKNOWN);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, FetchConfiguration.DEFAULT);
            assertEquals(LRSSizeAlgorithm.QUERY, fPlan.getLRSSizeAlgorithm());
            assertEquals(LRSSizes.SIZE_QUERY, fPlan.getLRSSize());
            assertEquals(LRSSizes.SIZE_QUERY, fConfig.getLRSSize());
        } catch (Exception e) {
            e.printStackTrace();
            fail("Unexpected " + e.getClass().getName());
        }
View Full Code Here

    public void testWriteLockLevelHint() {
        String hintName = "openjpa.WriteLockLevel";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager)em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
        em.getTransaction().begin();

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_NONE), LockModeType.NONE,
            MixedLockLevels.LOCK_NONE);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_NONE, LockModeType.NONE,
            MixedLockLevels.LOCK_NONE);

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_READ), LockModeType.READ,
            MixedLockLevels.LOCK_READ);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_READ, LockModeType.READ,
            MixedLockLevels.LOCK_READ);

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_WRITE), LockModeType.WRITE,
            MixedLockLevels.LOCK_WRITE);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_WRITE, LockModeType.WRITE,
            MixedLockLevels.LOCK_WRITE);

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_OPTIMISTIC), LockModeType.OPTIMISTIC,
            MixedLockLevels.LOCK_OPTIMISTIC);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_OPTIMISTIC, LockModeType.OPTIMISTIC,
            MixedLockLevels.LOCK_OPTIMISTIC);

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT),
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);

        writeLockLevelHintTest(fPlan, fConfig, hintName,
            String.valueOf(MixedLockLevels.LOCK_PESSIMISTIC_READ),
            LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_PESSIMISTIC_READ,
            LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);

        writeLockLevelHintTest(fPlan, fConfig, hintName,
            String.valueOf(MixedLockLevels.LOCK_PESSIMISTIC_WRITE),
            LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE,
            LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);

        writeLockLevelHintTest(fPlan, fConfig, hintName, String
            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT),
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
        writeLockLevelHintTest(fPlan, fConfig, hintName,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, FetchConfiguration.DEFAULT);
            assertEquals(MixedLockLevels.LOCK_WRITE, fConfig
                .getWriteLockLevel());
        } catch (Exception e) {
            fail("Unexpected " + e.getClass().getName());
        }
View Full Code Here

    private void fetchPlanReadLockModeHint(boolean inTransaction) {
        String hintName = "openjpa.FetchPlan.ReadLockMode";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
        if(inTransaction)
            em.getTransaction().begin();

        readLockModeHintTest(fPlan, fConfig, hintName, "none",
            LockModeType.NONE, MixedLockLevels.LOCK_NONE);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.NONE,
            LockModeType.NONE, MixedLockLevels.LOCK_NONE);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.NONE.name(), LockModeType.NONE,
            MixedLockLevels.LOCK_NONE);

        readLockModeHintTest(fPlan, fConfig, hintName, "read",
            LockModeType.READ, MixedLockLevels.LOCK_READ);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ,
            LockModeType.READ, MixedLockLevels.LOCK_READ);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.READ.name(), LockModeType.READ,
            MixedLockLevels.LOCK_READ);

        readLockModeHintTest(fPlan, fConfig, hintName, "write",
            LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE,
            LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE
            .name(), LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);

        readLockModeHintTest(fPlan, fConfig, hintName, "optimistic",
            LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.OPTIMISTIC,
            LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
        readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.OPTIMISTIC
            .name(), LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);

        readLockModeHintTest(fPlan, fConfig, hintName,
            "optimistic-force-increment",
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT.name(),
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);

        readLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-read", LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_READ, LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_READ.name(),
            LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);

        readLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-write", LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_WRITE, LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_WRITE.name(),
            LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);

        readLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-force-increment",
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
        readLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT.name(),
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
View Full Code Here

    private void fetchPlanWriteLockModeHint(boolean inTransaction) {
        String hintName = "openjpa.FetchPlan.WriteLockMode";

        EntityManager em = emf.createEntityManager();
        OpenJPAEntityManager oem = (OpenJPAEntityManager)em.getDelegate();
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
            ((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
        if(inTransaction)
            em.getTransaction().begin();

        writeLockModeHintTest(fPlan, fConfig, hintName, "none",
            LockModeType.NONE, MixedLockLevels.LOCK_NONE);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.NONE,
            LockModeType.NONE, MixedLockLevels.LOCK_NONE);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.NONE
            .name(), LockModeType.NONE, MixedLockLevels.LOCK_NONE);

        writeLockModeHintTest(fPlan, fConfig, hintName, "read",
            LockModeType.READ, MixedLockLevels.LOCK_READ);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ,
            LockModeType.READ, MixedLockLevels.LOCK_READ);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ
            .name(), LockModeType.READ, MixedLockLevels.LOCK_READ);

        writeLockModeHintTest(fPlan, fConfig, hintName, "write",
            LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE,
            LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE
            .name(), LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);

        writeLockModeHintTest(fPlan, fConfig, hintName,
            "optimistic", LockModeType.OPTIMISTIC,
            MixedLockLevels.LOCK_OPTIMISTIC);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.OPTIMISTIC, LockModeType.OPTIMISTIC,
            MixedLockLevels.LOCK_OPTIMISTIC);
        writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.OPTIMISTIC
            .name(), LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);

        writeLockModeHintTest(fPlan, fConfig, hintName,
            "optimistic-force-increment",
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.OPTIMISTIC_FORCE_INCREMENT.name(),
            LockModeType.OPTIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);

        writeLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-read", LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_READ, LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_READ.name(),
            LockModeType.PESSIMISTIC_READ,
            MixedLockLevels.LOCK_PESSIMISTIC_READ);

        writeLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-write", LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_WRITE, LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_WRITE.name(),
            LockModeType.PESSIMISTIC_WRITE,
            MixedLockLevels.LOCK_PESSIMISTIC_WRITE);

        writeLockModeHintTest(fPlan, fConfig, hintName,
            "pessimistic-force-increment",
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
        writeLockModeHintTest(fPlan, fConfig, hintName,
            LockModeType.PESSIMISTIC_FORCE_INCREMENT.name(),
            LockModeType.PESSIMISTIC_FORCE_INCREMENT,
            MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);

        try {
            fPlan.setHint(hintName, "xxxxx");
            fPlan.setHint(hintName, "yyyyy");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, "12345");
            fPlan.setHint(hintName, "67890");
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
        try {
            fPlan.setHint(hintName, -1);
            fPlan.setHint(hintName, -2);
            fail("Expecting a a IllegalArgumentException.");
        } catch (Exception e) {
            assertTrue("Caught expected exception",
                IllegalArgumentException.class.isAssignableFrom(e.getClass()));
        }
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    private void similarLockTimeoutHintsTest(OpenJPAEntityManager oem, String winner,
        Object expected, Object... hintNvalues) {
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.pushFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl) fPlan
            .getDelegate();

        for( int i = 0 ; i < hintNvalues.length ; i += 2) {
            fPlan.setHint((String)hintNvalues[i], hintNvalues[i+1]);
        }
        for( int i = 0 ; i < hintNvalues.length ; i += 2) {
            String hintName = (String)hintNvalues[i];
            Object expectedValue = hintNvalues[i+1];
            Object getValue = fPlan.getHint(hintName);
            if (hintName.equals(winner)) {
                assertEquals(expectedValue.getClass(), getValue.getClass());
                assertEquals(expectedValue, getValue);
            }
        }
        assertEquals(expected, fPlan.getLockTimeout());
        assertEquals(expected, fConfig.getLockTimeout());

        oem.popFetchPlan();
    }
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    private void similarQueryTimeoutHintsTest(OpenJPAEntityManager oem, String winner,
        Object expected, Object... hintNvalues) {
        JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.pushFetchPlan();
        JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl) fPlan
            .getDelegate();

        for( int i = 0 ; i < hintNvalues.length ; i += 2) {
            fPlan.setHint((String)hintNvalues[i], hintNvalues[i+1]);
        }
        for( int i = 0 ; i < hintNvalues.length ; i += 2) {
            String hintName = (String)hintNvalues[i];
            Object expectedValue = hintNvalues[i+1];
            Object getValue = fPlan.getHint(hintName);
            if (hintName.equals(winner)) {
                assertEquals(expectedValue.getClass(), getValue.getClass());
                assertEquals(expectedValue, getValue);
            }
        }
        assertEquals(expected, fPlan.getQueryTimeout());
        assertEquals(expected, fConfig.getQueryTimeout());

        oem.popFetchPlan();
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.jdbc.JDBCFetchPlan

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.