Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.Database


    }

    public void testUpdateChild() throws Exception {
        Lazy1to1Child child = null;

        Database db = _category.getDatabase();

        db.begin();
        child = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (2));
        assertChild(child, 2, "child 2");
        child.setDescription ("child 22");
        db.commit();

        db.begin();
        child = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (2));
        assertChild(child, 2, "child 22");
        db.rollback();

        db.begin();
        child = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (2));
        assertChild(child, 2, "child 22");
        child.setDescription("child 2");
        db.commit();

        db.begin();
        child = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (2));
        assertChild(child, 2, "child 2");
        db.rollback();

        db.close();
    }
View Full Code Here


    public void testUpdateParentMemberWithAccess() throws Exception {
        Lazy1to1Parent parent = null;
        Lazy1to1Child child = null;
       
        Database db = _category.getDatabase();
       
        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        child = parent.getChild();
        assertChild(child, 1, "child 1");
        parent.setDescription("parent 11");
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 11");
        child = parent.getChild();
        assertChild(child, 1, "child 1");
        db.rollback();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 11");
        child = parent.getChild();
        assertChild(child, 1, "child 1");
        parent.setDescription("parent 1");
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        child = parent.getChild();
        assertChild(child, 1, "child 1");
        db.rollback();

        db.close();
    }
View Full Code Here

    }

    public void testUpdateParentMemberWithoutAccess() throws Exception {
        Lazy1to1Parent parent = null;
       
        Database db = _category.getDatabase();
       
        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        parent.setDescription("parent 11");
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 11");
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 11");
        parent.setDescription("parent 1");
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        db.commit();

        db.close();
    }
View Full Code Here

   
    public void testUpdateParentSetChildToNullWithAccess() throws Exception {
        Lazy1to1Parent parent = null;
        Lazy1to1Child childNew = null;
       
        Database db = _category.getDatabase();
       
        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        assertChild(parent.getChild(), 1, "child 1");
        parent.setChild(null);
        db.commit();
       
        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        assertNull(parent.getChild());
        db.rollback();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        childNew = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (1));
        assertChild(childNew, 1, "child 1");
        parent.setChild(childNew);
        db.commit();

        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (1));
        assertParent(parent, 1, "parent 1");
        assertChild(parent.getChild(), 1, "child 1");
        db.rollback();

        db.close();
    }
View Full Code Here

        assertEquals(id, nature.getId().intValue());
        assertEquals(description, nature.getDescription());
    }
   
    public void testLoadBookWithLazyAuthorProperty() throws Exception {
        Database db1 = _category.getDatabase();
        db1.begin();

        try {
            db1.load(Lazy1to1Author.class, new Long(1));
        } catch (ObjectNotFoundException e) {
            fail("Database should contain an author with id=1");
        }

        Database db2 = _category.getDatabase();
        db2.begin();

        OQLQuery qry = db2.getOQLQuery(
                "SELECT o FROM " + Lazy1to1Book.class.getName() + " o");
        QueryResults results = qry.execute();
        assertTrue("Couldn't find the book in db: ", results.hasMore());

        Lazy1to1Book book = null;
        if (results.hasMore()) {
            book = (Lazy1to1Book) results.next();
            Lazy1to1Author currentAuthor = book.getAuthor();

            assertNotNull("book should have author", currentAuthor);
            assertNotNull("author should have a last name", currentAuthor.getLastName());
        }

        db2.commit();
        db2.close();

        if (db1 != null) {
            try {
                db1.commit();
            } catch (Exception ex) {
View Full Code Here

     * Create the requisite objects in the database
     * @throws Exception A general exception.
     */
    private void createTestDataSet() throws Exception {
        LOG.info("creating test data set...");
        Database db = null;
        try {
            db = this._category.getDatabase();
            db.begin();

            LazyEmployee person = new LazyEmployee();
            person.setFirstName("First");
            person.setLastName("Person");
            person.setBirthday(JDO_ORIGINAL_DATE);
            person.setStartDate(JDO_ORIGINAL_DATE);

            LazyAddress address1 = new LazyAddress();
            address1.setId(1);
            address1.setStreet(Integer.toString(1) + JDO_ORIGINAL_STRING);
            address1.setCity("First City");
            address1.setState("AB");
            address1.setZip("10000");
            address1.setPerson(person);

            LazyAddress address2 = new LazyAddress();
            address2.setId(2);
            address2.setStreet(Integer.toString(2) + JDO_ORIGINAL_STRING);
            address2.setCity("Second City");
            address2.setState("BC");
            address2.setZip("22222");
            address2.setPerson(person);

            LazyAddress address3 = new LazyAddress();
            address3.setId(3);
            address3.setStreet(Integer.toString(3) + JDO_ORIGINAL_STRING);
            address3.setCity("Third Ave");
            address3.setState("AB");
            address3.setZip("30003");
            address3.setPerson(person);

            ArrayList addresslist = new ArrayList();
            addresslist.add(address1);
            addresslist.add(address2);
            addresslist.add(address3);

            person.setAddress(addresslist);

            LazyPayRoll pr1 = new LazyPayRoll();
            pr1.setId(1);
            pr1.setHoliday(15);
            pr1.setHourlyRate(25);
            pr1.setEmployee(person);
            person.setPayRoll(pr1);

            LazyContractCategory cc = new LazyContractCategory();
            cc.setId(101);
            cc.setName("Full-time slave");
            db.create(cc);

            LazyContractCategory cc2 = new LazyContractCategory();
            cc2.setId(102);
            cc2.setName("Full-time employee");
            db.create(cc2);
           
            ArrayList category = new ArrayList();
            category.add(cc);
            category.add(cc2);

            LazyContract con = new LazyContract();
            con.setPolicyNo(1001);
            con.setComment("80 hours a week, no pay hoilday, "
                    + "no sick leave, arrive office at 7:30am everyday");
            con.setContractNo(78);
            con.setEmployee(person);
            con.setCategory(category);
            person.setContract(con);
           
            db.create(person);
           
            db.commit();
            db.close();
        } catch (Exception e) {
            LOG.error("createTestDataSet: exception caught", e);
            throw e;
        }
    }
View Full Code Here

     * @return True if read transaction is valid.
     */
    private boolean validReadTransaction(final String firstName, final String lastName) {
        LOG.info("validating read transaction for person "
                + firstName + " " + lastName + "...");
        Database db = null;
        boolean valid = true;
        try {
            db = _category.getDatabase();
            db.begin();
           
            Identity fullname = new Identity("First", "Person");
            LazyEmployee person;
           
            person = (LazyEmployee) db.load(LazyEmployee.class, fullname);
            if (person.getBirthday().compareTo(JDBC_UPDATED_DATE) != 0) {
                LOG.debug("validReadTransaction: birthdate for "
                        + person.getFirstName() + " " + person.getLastName()
                        + " does not match expected value, value: "
                        + person.getBirthday().toString()
                        + ", expected: " + JDBC_UPDATED_DATE.toString());
                valid = false;
            }
            if (person.getStartDate().compareTo(JDBC_UPDATED_DATE) != 0) {
                LOG.debug("validReadTransaction: start date for "
                        + person.getFirstName() + " " + person.getLastName()
                        + " does not match expected value, value: "
                        + person.getStartDate().toString()
                        + ", expected: " + JDBC_UPDATED_DATE.toString());
                valid = false;
            }
            Iterator itor = person.getAddress().iterator();
            while (itor.hasNext()) {
                LazyAddress address = (LazyAddress) itor.next();
                String expectedStreet = new String(
                        Integer.toString(address.getId()) + JDBC_UPDATED_STRING);
                if (address.getStreet().compareTo(expectedStreet) != 0) {
                    LOG.debug("validReadTransaction: street in address "
                            + address.getId()
                            + " does not match expected value, value: "
                            + address.getStreet()
                            + ", expected: " + expectedStreet);
                    valid = false;
                }
            }
            db.rollback();
            db.close();
        } catch (Exception e) {
            if (db != null) {
                try {
                    db.close();
                } catch (Exception se) {
                    LOG.warn("Problem closing Database instance.", se);
                }
            }
            LOG.error("validReadTransaction: exception while validating read for "
View Full Code Here

     * @return True if write transaction is valid.
     */
    private boolean validWriteTransaction(final String firstName, final String lastName) {
        LOG.info("validating write transaction for group "
                + firstName + " " + lastName + "...");
        Database db = null;
        try {
            db = _category.getDatabase();
            db.begin();
           
            Identity fullname = new Identity("First", "Person");
            LazyEmployee person;
           
            person = (LazyEmployee) db.load(LazyEmployee.class, fullname);
            person.setBirthday(JDO_UPDATED_DATE);
            Iterator itor = person.getAddress().iterator();
            while (itor.hasNext()) {
                LazyAddress address = (LazyAddress) itor.next();
                String newStreet = new String(
                        Integer.toString(address.getId()) + JDO_UPDATED_STRING);
                address.setStreet(newStreet);
            }
            db.commit();
            db.close();
        } catch (Exception e) {
            if (db != null) {
                try {
                    db.close();
                } catch (Exception se) {
                    LOG.warn("Problem closing Database instance.", se);
                }
            }
            LOG.error("validWriteTransaction: exception while validating write for "
View Full Code Here

     *             if something goes wrong
     */
    public void testLoadBook() throws Exception {
        // Assertion.assertEquals(new XmlDataSet(new
        // FileInputStream(getClass().getResource(DATA_SET_FILE).getFile())),getConnection().createDataSet());
        Database db = _jdo.getDatabase();
        assertNotNull(db);
        db.begin();

        Book lookup = (Book) db.load(Book.class, new Long(1234));
        assertNotNull(lookup);

        assertEquals(1234, lookup.getIsbn());
        assertEquals("Heart of Darkness", lookup.getTitle());

        db.commit();
        db.close();
    }
View Full Code Here

        db.commit();
        db.close();
    }

    public void testCreateBook() throws Exception {
        Database db = _jdo.getDatabase();
        assertNotNull(db);

        Book myBook = new Book();
        myBook.setIsbn(1235);
        myBook.setTitle("My Definition");

        db.begin();
        db.create(myBook);
        db.commit();

        db.begin();
        Book lookup = (Book) db.load(Book.class, new Long(1235));
        assertNotNull(lookup);
        assertEquals(1235, lookup.getIsbn());
        assertEquals("My Definition", lookup.getTitle());
        db.commit();
        db.close();
        assertDataset(DATA_SET_FILE_INSERTED);
    }
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.Database

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.