Package org.apache.openjpa.persistence.kernel.common.apps

Examples of org.apache.openjpa.persistence.kernel.common.apps.Blobs


    // blob tests
    public void testBlobSetToNull() {

        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        Blobs lobs = new Blobs();
        lobs.setLobNotNullable(null);
        lobs.setLobNullable(null);
        em.persist(lobs);
        try {
            em.getTransaction().commit();
            fail("Expected a RollbackException");
        } catch (Exception e) {
View Full Code Here


    }
   
    public void testBlobPersistQuery() {
        // test with null
        EntityManager em = emf.createEntityManager();
        Blobs lobs = new Blobs();
        byte[] bytes = new byte[10];
        for (int i = 0; i < bytes.length; i++)
            bytes[i] = randomByte().byteValue();

        em.getTransaction().begin();
        lobs.setLobNotNullable(bytes);
        lobs.setLobNullable(null);
        em.persist(lobs);
        em.getTransaction().commit();
        em.close();
       
        em = emf.createEntityManager();
        em.getTransaction().begin();
        Query query = em.createQuery("select e from Blobs e");
        lobs = (Blobs)query.getSingleResult();
        assertTrue(lobs.getLobNullable() == null || lobs.getLobNullable().length == 0);   // still an empty string
        em.remove(lobs);
        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

    public void testBlobZeroLengthByteArray() throws Exception {
        // test with 0 length bytes
        byte[] bytes = new byte[0];
        EntityManager em = emf.createEntityManager();
        Blobs lobs = new Blobs();
       
        em.getTransaction().begin();
        lobs.setLobNotNullable(bytes);
        lobs.setLobNullable(bytes);
        em.persist(lobs);
        try {
            em.getTransaction().commit();
        } catch (Exception e) {
            if (getDBDictionary() instanceof SybaseDictionary) {
                assertTrue(e instanceof RollbackException);
                return;
            } else {
                throw e;
            }
        }
        em.close();

        em = emf.createEntityManager();
        em.getTransaction().begin();
        Query query = em.createQuery("select e from Blobs e");
        lobs = (Blobs)query.getSingleResult();
        assertTrue(lobs.getLobNullable() == null || lobs.getLobNullable().length == 0);
        assertTrue(lobs.getLobNotNullable() == null || lobs.getLobNotNullable().length == 0);
        for (int i = 0; i < bytes.length; i++) {
            assertEquals(bytes[i], lobs.getLobNullable()[i]);
        }
        em.remove(lobs);
        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

        byte[] bytes = new byte[5000];
        for (int i = 0; i < bytes.length; i++)
            bytes[i] = randomByte().byteValue();

        EntityManager em = emf.createEntityManager();
        Blobs lobs = new Blobs();
        em.getTransaction().begin();
        lobs.setLobNotNullable(bytes);
        lobs.setLobNullable(bytes);
        em.persist(lobs);
        em.getTransaction().commit();
        em.close();

        em = emf.createEntityManager();
        em.getTransaction().begin();
        Query query = em.createQuery("select e from Blobs e");
        lobs = (Blobs)query.getSingleResult();
        for (int i = 0; i < 5000; i++) {
            assertEquals(lobs.getLobNullable()[i], lobs.getLobNotNullable()[i]);
            assertEquals(bytes[i], lobs.getLobNullable()[i]);
        }
        em.remove(lobs);
        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.kernel.common.apps.Blobs

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.