Package de.huepattl.playground.berkeleydb.domain.model

Examples of de.huepattl.playground.berkeleydb.domain.model.SimplePerson


     * @see #persistWithSubobjects()
     * @see #setupDatabase()
     */
    @Test
    public void simplePersistence() throws Exception {
        SimplePerson personToPersist;
        SimplePerson personFromDatabase;
        /*
         * The index is our persistence interface. It is described by the primary key data type (long),
         * which refers to the ID entity, and the entity type itself.
         */
        PrimaryIndex<Long, SimplePerson> primaryIndex;

        /*
         * Create example entity. Please have a look at that class and pay attention to its annotations
         * that are required for that entity in order to be persisted and retrieved.
         * Note that we do NOT specify the identifier (ID).
         */
        {
            personToPersist = new SimplePerson();
            personToPersist.setLastName("Doe");
            personToPersist.setFirstName("John");
        }

        /*
         * All entities are identified by their primary key (ID). Therefore we create a
         * typed index and persis the object. By using put() instead of putNoReturn(),
         * the passed entity will be updated accordingly.
         * A bit strange: out() also returns the entity in case of UPDATE, but it will
         * be NULL for INSERT. FIXME
         */
        {
            primaryIndex = entityStore.getPrimaryIndex(Long.class, SimplePerson.class);

            LOG.info("Object BEFORE persisting: " + personToPersist.toString());
            primaryIndex.put(personToPersist);
            LOG.info("Object AFTER persisting: " + personToPersist.toString()
                    + " (now with ID!");
        }

        /*
         * Retrieve object from database and compare if it equals the original one.
         * We use the ID from the original update (put() returned the updated entity
         * with the ID that we can use here...).
         */
        {
            final long id = personToPersist.getId();
            personFromDatabase = primaryIndex.get(id);

            assertNotNull(personFromDatabase);
            LOG.info("Object retrieved from store: " + personFromDatabase.toString());
            assertEquals(personToPersist.getLastName(), personFromDatabase.getLastName());
            assertEquals(personToPersist.getFirstName(), personFromDatabase.getFirstName());
        }
    }
View Full Code Here


     * @throws Exception BAM!
     */
    @Test
    public void persistWithSubobjects() throws Exception {
        PrimaryIndex<Long, SimplePerson> primaryIndex = entityStore.getPrimaryIndex(Long.class, SimplePerson.class);
        SimplePerson personToPersist;
        SimplePerson person;

        /*
         * Create person object with owned contacts object.
         */
        {
            Contacts contacts;
            contacts = new Contacts();
            contacts.setMobilePhone("+555-1234");
            contacts.setPhone("+555-2345");
            contacts.setEmail("johndoe@example.com");
            contacts.setStreet("Middle-Of-Nowhere 231");
            contacts.setCity("Shell Beach");
            contacts.setZip("101");

            personToPersist = new SimplePerson("Doe", "John", contacts);
        }

        /*
         * Persist and log/show updated object.
         */
        LOG.info("Object to persist: " + personToPersist + ", " + personToPersist.getContacts());
        primaryIndex.put(personToPersist);
        person = primaryIndex.get(personToPersist.getId());
        LOG.info("Object retrieved from store: " + person + ", " + person.getContacts());
    }
View Full Code Here

TOP

Related Classes of de.huepattl.playground.berkeleydb.domain.model.SimplePerson

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.