Search in sources :

Example 6 with UserGroup

use of org.neo4j.ogm.domain.gh824.UserGroup in project tests by datanucleus.

the class AttachDetachReplicateTest method testReplicateApplicationIdentityWith1toN.

public void testReplicateApplicationIdentityWith1toN() {
    PersistenceManagerFactory pmf1 = null;
    PersistenceManagerFactory pmf2 = null;
    try {
        // Connect to "datastore1"
        Properties props = new Properties();
        props.setProperty(PropertyNames.PROPERTY_ATTACH_SAME_DATASTORE, "false");
        props.setProperty(PropertyNames.PROPERTY_AUTOSTART_MECHANISM, "Classes");
        props.setProperty(PropertyNames.PROPERTY_AUTOSTART_CLASSNAMES, "org.datanucleus.samples.one_many.unidir_2.GroupMember,org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember," + "org.datanucleus.samples.one_many.unidir_2.UserGroup,org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup");
        pmf1 = getPMF(1, props);
        // Persist data to "datastore1"
        PersistenceManager pm1 = pmf1.getPersistenceManager();
        Transaction tx1 = pm1.currentTransaction();
        Object holderId = null;
        try {
            tx1.begin();
            ModeratedUserGroup holder = new ModeratedUserGroup(1, "HolderA", "First A");
            List<GroupMember> elements = new ArrayList<GroupMember>();
            elements.add(new ExpertGroupMember(25, "ElementB1", "First B"));
            elements.add(new ExpertGroupMember(26, "ElementB2", "Second B"));
            elements.add(new GroupMember(27, "ElementB3"));
            elements.add(new GroupMember(28, "ElementB4"));
            holder.setMembers(elements);
            pm1.makePersistent(holder);
            tx1.commit();
            holderId = JDOHelper.getObjectId(holder);
        } catch (Exception e) {
            LOG.error("Exception thrown creating data in datastore 1", e);
            e.printStackTrace();
            return;
        } finally {
            if (tx1.isActive()) {
                tx1.rollback();
            }
            pm1.close();
        }
        // Detach holder from "datastore1"
        UserGroup detachedHolder = null;
        pm1 = pmf1.getPersistenceManager();
        tx1 = pm1.currentTransaction();
        try {
            pm1.getFetchPlan().setGroups(new String[] { FetchPlan.DEFAULT, FetchPlan.ALL });
            pm1.getFetchPlan().setMaxFetchDepth(-1);
            tx1.begin();
            ModeratedUserGroup holder = (ModeratedUserGroup) pm1.getObjectById(holderId);
            detachedHolder = (ModeratedUserGroup) pm1.detachCopy(holder);
            tx1.commit();
        } catch (Exception e) {
            LOG.error("Exception thrown detaching data from datastore 1", e);
            fail("Exception in detach with datastore 1 : " + e.getMessage());
        } finally {
            if (tx1.isActive()) {
                tx1.rollback();
            }
            pm1.close();
        }
        // Connect to "datastore2"
        pmf2 = getPMF(2, props);
        // Attach data to "datastore2"
        PersistenceManager pm2 = pmf2.getPersistenceManager();
        Transaction tx2 = pm2.currentTransaction();
        try {
            tx2.begin();
            pm2.makePersistent(detachedHolder);
            tx2.commit();
        } catch (Exception e) {
            LOG.error("Exception thrown attaching data to datastore 2", e);
            fail("Exception in attach with datastore 2 : " + e.getMessage());
        } finally {
            if (tx2.isActive()) {
                tx2.rollback();
            }
            pm2.close();
        }
    } catch (Exception e) {
        fail("Exception on attach to datastore 2 : " + e.getMessage());
    } finally {
        // Clean out our data
        clean(ModeratedUserGroup.class);
        clean(UserGroup.class);
        clean(ExpertGroupMember.class);
        clean(GroupMember.class);
    }
}
Also used : ModeratedUserGroup(org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup) GroupMember(org.datanucleus.samples.one_many.unidir_2.GroupMember) ExpertGroupMember(org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) ExpertGroupMember(org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember) ArrayList(java.util.ArrayList) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) Properties(java.util.Properties) JDOException(javax.jdo.JDOException) JDOUserException(javax.jdo.JDOUserException) UserGroup(org.datanucleus.samples.one_many.unidir_2.UserGroup) ModeratedUserGroup(org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup)

Example 7 with UserGroup

use of org.neo4j.ogm.domain.gh824.UserGroup in project neo4j-ogm by neo4j.

the class DeepNestQueryingOfRelationshipEntitiesIntegrationTest method createData.

@Before
public void createData() {
    sessionFactory.openSession().purgeDatabase();
    Address a1 = new Address();
    a1.setCode("0001");
    Address a2 = new Address();
    a2.setCode("0002");
    City aachen = new City("Aachen");
    City koeln = new City("Köln");
    a2.setCity(aachen);
    User u1 = new User("U1");
    u1.setAddress(a1);
    User u2 = new User("Mr. User");
    u2.setAddress(a1);
    User u3 = new User();
    u3.setAddress(a2);
    UserGroup ug1 = new UserGroup();
    ug1.setCity(aachen);
    ug1.setName("EuregJUG");
    UserGroup ug2 = new UserGroup();
    ug2.setCity(koeln);
    ug2.setName("JUG Köln");
    List<GroupMember> members = Arrays.asList(new GroupMember(u1, ug1), new GroupMember(u2, ug2), new GroupMember(u3, ug2));
    Session session = sessionFactory.openSession();
    members.forEach(session::save);
}
Also used : GroupMember(org.neo4j.ogm.domain.gh824.GroupMember) User(org.neo4j.ogm.domain.gh824.User) Address(org.neo4j.ogm.domain.gh824.Address) City(org.neo4j.ogm.domain.gh824.City) UserGroup(org.neo4j.ogm.domain.gh824.UserGroup) Session(org.neo4j.ogm.session.Session) Before(org.junit.Before)

Example 8 with UserGroup

use of org.neo4j.ogm.domain.gh824.UserGroup in project tests by datanucleus.

the class JDOQLBasicTest method testQueryUnboundVariablesInheritanceRightHandDeclared2.

public void testQueryUnboundVariablesInheritanceRightHandDeclared2() {
    try {
        ModeratedUserGroup grp1 = new ModeratedUserGroup(1, "JDO Expert Group");
        ModeratedUserGroup grp2 = new ModeratedUserGroup(1, "JPA Expert Group");
        ModeratedUserGroup grp3 = new ModeratedUserGroup(1, "J2EE Expert Group");
        ExpertGroupMember mem1 = new ExpertGroupMember(1, "Craig Russell");
        ExpertGroupMember mem2 = new ExpertGroupMember(1, "Linda De Michiel");
        ExpertGroupMember mem3 = new ExpertGroupMember(1, "Bill Shannon");
        grp1.getMembers().add(mem1);
        grp2.getMembers().add(mem2);
        grp3.getMembers().add(mem2);
        grp3.getMembers().add(mem3);
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            pm.makePersistent(grp1);
            pm.makePersistent(grp2);
            pm.makePersistent(grp3);
            tx.commit();
            tx.begin();
            Query q = pm.newQuery(pm.getExtent(UserGroup.class, true));
            Collection c = q.filter("(mem.name == \"Craig Russell\") && this.members.contains(mem)").variables("ExpertGroupMember mem").imports("import org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember").executeList();
            assertEquals(1, c.size());
            assertEquals(((UserGroup) c.iterator().next()).getName(), "JDO Expert Group");
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        // Clean out our data
        clean(ModeratedUserGroup.class);
        clean(ExpertGroupMember.class);
    }
}
Also used : ModeratedUserGroup(org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) ExpertGroupMember(org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember) Collection(java.util.Collection) UserGroup(org.datanucleus.samples.one_many.unidir_2.UserGroup) ModeratedUserGroup(org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup)

Aggregations

ArrayList (java.util.ArrayList)5 UserGroup (org.datanucleus.samples.one_many.unidir_2.UserGroup)5 List (java.util.List)4 PersistenceManager (javax.jdo.PersistenceManager)4 Transaction (javax.jdo.Transaction)4 EntityManager (javax.persistence.EntityManager)3 EntityTransaction (javax.persistence.EntityTransaction)3 ExpertGroupMember (org.datanucleus.samples.one_many.unidir_2.ExpertGroupMember)3 GroupMember (org.datanucleus.samples.one_many.unidir_2.GroupMember)3 ModeratedUserGroup (org.datanucleus.samples.one_many.unidir_2.ModeratedUserGroup)3 Collection (java.util.Collection)2 Query (javax.jdo.Query)2 ExpertGroupMember (org.datanucleus.samples.annotations.one_many.unidir_2.ExpertGroupMember)2 GroupMember (org.datanucleus.samples.annotations.one_many.unidir_2.GroupMember)2 ModeratedUserGroup (org.datanucleus.samples.annotations.one_many.unidir_2.ModeratedUserGroup)2 UserGroup (org.datanucleus.samples.annotations.one_many.unidir_2.UserGroup)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 JDOException (javax.jdo.JDOException)1 JDOUserException (javax.jdo.JDOUserException)1