Package com.mysql.clusterj.jpatest.model

Examples of com.mysql.clusterj.jpatest.model.LongLongStringPKOneMany


    /** This tests delete, insert, find, and update of entities with compound
     * primary and foreign keys.
     */
    public void test() {
        LongLongStringPKOneMany a;
        em = emf.createEntityManager();
        begin();
        // bulk remove all LongLongStringFKManyOne
        int countB = em.createQuery("DELETE FROM LongLongStringFKManyOne").executeUpdate();
        int countA = em.createQuery("DELETE FROM LongLongStringPKOneMany").executeUpdate();
        print ("Deleted " + countB + " instances of LongLongStringFKManyOne " +
                countA + " instances of LongLongStringFKManyOne ");
        commit();
        em.close();

        em = emf.createEntityManager();
        begin();
        print("Creating " + NUMBER_OF_A + " instances of LongLongStringPKOneMany.");
        for (int i = OFFSET_A; i < OFFSET_A + NUMBER_OF_A; ++i) {
            a0 = LongLongStringPKOneMany.create(i);
            em.persist(a0);
        }
        Collection<LongLongStringFKManyOne> bs = new HashSet<LongLongStringFKManyOne>();
        print("Creating " + NUMBER_OF_B + " instances of LongLongStringFKManyOne.");
        for (int i = OFFSET_B; i < OFFSET_B + NUMBER_OF_B; ++i) {
            LongLongStringFKManyOne b = LongLongStringFKManyOne.create(i);
            b.setLongLongStringPKRelationship(a0);
            bs.add(b);
            em.persist(b);
        }
        a0.setLongLongStringFKRelationships(bs);
        print("Before commit, " + a0.toString());
        for (LongLongStringFKManyOne b:bs){print(b.toString());}
        commit();
        em.close();

        em = emf.createEntityManager();
        print("Finding " + NUMBER_OF_A + " instances of LongLongStringPKOneMany.");
        begin();
        for (int i = OFFSET_A; i < OFFSET_A + NUMBER_OF_A; ++i) {
            LongLongStringOid oid = new LongLongStringOid(i);
            a = em.find(LongLongStringPKOneMany.class, oid);
        }
        print("Finding " + NUMBER_OF_B + " instances of LongLongStringFKManyOne.");
        for (int i = OFFSET_B; i < OFFSET_B + NUMBER_OF_B; ++i) {
            LongLongStringOid oid = new LongLongStringOid(i);
            LongLongStringFKManyOne b = em.find(LongLongStringFKManyOne.class, oid);
            print(b.toString());
        }
        commit();
        em.close();

        /** Update every other instance of B to refer to a different A. */
        em = emf.createEntityManager();
        print("Finding 1 instance of A.");
        begin();
        LongLongStringOid oid = new LongLongStringOid(OFFSET_A);
        a = em.find(LongLongStringPKOneMany.class, oid);
        print("Finding 2 instances of B.");
        for (int i = OFFSET_B; i < OFFSET_B + NUMBER_OF_B; i += 2) {
            oid = new LongLongStringOid(i);
            LongLongStringFKManyOne b = em.find(LongLongStringFKManyOne.class, oid);
            // update every other one
            b.setLongLongStringPKRelationship(a);
            print(b.toString());
        }
        print("After update: " + a0.toString());
        commit();
        em.close();

        em = emf.createEntityManager();
        print("Finding " + NUMBER_OF_A + " instances of A.");
        begin();
        for (int i = OFFSET_A; i < OFFSET_A + NUMBER_OF_A; ++i) {
            oid = new LongLongStringOid(i);
            a = em.find(LongLongStringPKOneMany.class, oid);
            as.add(a);
            print(a.toString());
        }
        print("Finding " + NUMBER_OF_B + " instances of B.");
        for (int i = OFFSET_B; i < OFFSET_B + NUMBER_OF_B; ++i) {
            oid = new LongLongStringOid(i);
            LongLongStringFKManyOne b = em.find(LongLongStringFKManyOne.class, oid);
View Full Code Here

TOP

Related Classes of com.mysql.clusterj.jpatest.model.LongLongStringPKOneMany

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.