Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.Database


        database.close();
    }

    public void testLoadAndUpdateLaptopRollback() throws Exception {
        Database database = _category.getDatabase();
       
        database.begin();
        Laptop laptop = (Laptop) database.load(Laptop.class, new Integer(1));
        database.commit();
       
        assertNotNull(laptop);
        assertEquals("ctf.jdo.tc9x.Laptop", laptop.getClass().getName());
        assertEquals(1, laptop.getId());
        assertEquals("laptop 1", laptop.getName());
       
        laptop.setName("laptop 1x");

        database.begin();
        database.update(laptop);
        database.commit();
       
        database.begin();
        laptop = (Laptop) database.load(Laptop.class, new Integer(1));
        database.commit();
       
        assertNotNull(laptop);
        assertEquals("ctf.jdo.tc9x.Laptop", laptop.getClass().getName());
        assertEquals(1, laptop.getId());
        assertEquals("laptop 1x", laptop.getName());

        laptop.setName("laptop 1");

        database.begin();
        database.update(laptop);
        database.rollback();
       
        database.begin();
        laptop = (Laptop) database.load(Laptop.class, new Integer(1));
        database.commit();

        assertNotNull(laptop);
        assertEquals("ctf.jdo.tc9x.Laptop", laptop.getClass().getName());
        assertEquals(1, laptop.getId());
        assertEquals("laptop 1x", laptop.getName());

        laptop.setName("laptop 1");

        database.begin();
        database.update(laptop);
        database.commit();
       
        database.begin();
        laptop = (Laptop) database.load(Laptop.class, new Integer(1));
        database.commit();

        assertNotNull(laptop);
        assertEquals("ctf.jdo.tc9x.Laptop", laptop.getClass().getName());
        assertEquals(1, laptop.getId());
        assertEquals("laptop 1", laptop.getName());
        database.close();
    }
View Full Code Here


    }
   
    public void testReadOnlyOidOnly() throws Exception {
        long start = System.currentTimeMillis();
       
        Database db = _jdo.getDatabase();
        db.begin();
       
        long begin = System.currentTimeMillis();
       
        OQLQuery query = db.getOQLQuery(
                "CALL SQL select PTF_LOCKED.ID as ID "
              + "from PTF_LOCKED order by PTF_LOCKED.ID "
              + "AS " + OID.class.getName());
        QueryResults results = query.execute(Database.READONLY);
       
        long result = System.currentTimeMillis();
       
        int count = 0;
        while (results.hasMore()) {
            results.next();
            count++;
        }
       
        long iterate = System.currentTimeMillis();
       
        db.commit();
       
        long commit = System.currentTimeMillis();
       
        db.close();

        long close = System.currentTimeMillis();
       
        LOG.info(format("ReadOnlyOidOnly",
                         DF.format(begin - start),
View Full Code Here

        assertEquals("laptop 1", laptop.getName());
        database.close();
    }

    public void testLoadAndUpdateCar() throws Exception {
        Database database = _category.getDatabase();
       
        database.begin();
        Truck truck = (Truck) database.load(Truck.class, new Integer(5));
        database.commit();
       
        assertNotNull(truck);
        assertEquals("ctf.jdo.tc9x.Truck", truck.getClass().getName());
        assertEquals(5, truck.getId());
        assertEquals("truck 5", truck.getName());
       
        truck.setName("truck 5t");

        database.begin();
        database.update(truck);
        database.commit();
       
        database.begin();
        truck = (Truck) database.load(Truck.class, new Integer(5));
        database.commit();
       
        assertNotNull(truck);
        assertEquals("ctf.jdo.tc9x.Truck", truck.getClass().getName());
        assertEquals(5, truck.getId());
        assertEquals("truck 5t", truck.getName());

        truck.setName("truck 5");

        database.begin();
        database.update(truck);
        database.commit();
       
        database.begin();
        truck = (Truck) database.load(Truck.class, new Integer(5));
        database.commit();

        assertNotNull(truck);
        assertEquals("ctf.jdo.tc9x.Truck", truck.getClass().getName());
        assertEquals(5, truck.getId());
        assertEquals("truck 5", truck.getName());

        database.close();
    }
View Full Code Here

        database.close();
    }

    public void testLoadAndUpdateTruck() throws Exception {
        Database database = _category.getDatabase();
       
        database.begin();
        Car car = (Car) database.load(Car.class, new Integer(5));
        database.commit();
       
        assertNotNull(car);
        assertEquals("ctf.jdo.tc9x.Car", car.getClass().getName());
        assertEquals(5, car.getId());
        assertEquals("truck 5", car.getName());
       
        car.setName("truck 5t");

        database.begin();
        database.update(car);
        database.commit();
       
        database.begin();
        car = (Car) database.load(Car.class, new Integer(5));
        database.commit();
       
        assertNotNull(car);
        assertEquals("ctf.jdo.tc9x.Car", car.getClass().getName());
        assertEquals(5, car.getId());
        assertEquals("truck 5t", car.getName());

        car.setName("truck 5");

        database.begin();
        database.update(car);
        database.commit();
       
        database.begin();
        car = (Car) database.load(Car.class, new Integer(5));
        database.commit();

        assertNotNull(car);
        assertEquals("ctf.jdo.tc9x.Car", car.getClass().getName());
        assertEquals(5, car.getId());
        assertEquals("truck 5", car.getName());

        database.close();
    }
View Full Code Here

    private void createTestDataSet() throws Exception {
        log("creating test data set...");
        ManyGroup groupA, groupB, groupC, groupD;
        ManyPerson person1, person2, person3, person4;
        ArrayList al, bl, c1, d1;
        Database db = null;
        try {
            db = this._category.getDatabase();
            db.begin();

            //
            // create four persons
            //
            person1 = new ManyPerson();
            ArrayList gPerson1 = new ArrayList();
            person1.setId(_person1Id);
            person1.setGroup(gPerson1);
            person1.setSthelse("Something else");
            person1.setHelloworld("Hello World!");
            person1.setValue1(JDO_ORIGINAL_VALUE);

            person2 = new ManyPerson();
            ArrayList gPerson2 = new ArrayList();
            person2.setId(_person2Id);
            person2.setGroup(gPerson2);
            person2.setSthelse("Something else");
            person2.setHelloworld("Hello World!");
            person2.setValue1(JDO_ORIGINAL_VALUE);

            person3 = new ManyPerson();
            ArrayList gPerson3 = new ArrayList();
            person3.setId(_person3Id);
            person3.setGroup(gPerson3);
            person3.setSthelse("Something else for person 3");
            person3.setHelloworld("Hello World!");
            person3.setValue1(JDO_ORIGINAL_VALUE);

            person4 = new ManyPerson();
            ArrayList gPerson4 = new ArrayList();
            person4.setId(_person4Id);
            person4.setGroup(gPerson4);
            person4.setSthelse("Something else for person 4");
            person4.setHelloworld("Hello World!");
            person4.setValue1(JDO_ORIGINAL_VALUE);

            //
            // create four groups, assign all persons to each group
            //
            groupA = new ManyGroup();
            groupA.setValue1(JDO_ORIGINAL_VALUE);
            al = new ArrayList();
            al.add(person1);
            al.add(person2);
            al.add(person3);
            al.add(person4);
            groupA.setId(_groupAId);
            groupA.setPeople(al);

            groupB = new ManyGroup();
            groupB.setValue1(JDO_ORIGINAL_VALUE);
            groupB.setId(_groupBId);
            bl = new ArrayList();
            bl.add(person1);
            bl.add(person2);
            bl.add(person3);
            bl.add(person4);
            groupB.setPeople(bl);

            groupC = new ManyGroup();
            groupC.setValue1(JDO_ORIGINAL_VALUE);
            c1 = new ArrayList();
            c1.add(person1);
            c1.add(person2);
            c1.add(person3);
            c1.add(person4);
            groupC.setId(_groupCId);
            groupC.setPeople(c1);

            groupD = new ManyGroup();
            groupD.setValue1(JDO_ORIGINAL_VALUE);
            d1 = new ArrayList();
            d1.add(person1);
            d1.add(person2);
            d1.add(person3);
            d1.add(person4);
            groupD.setId(_groupDId);
            groupD.setPeople(d1);

            //
            // assign all groups to each person
            //
            gPerson1.add(groupA);
            gPerson1.add(groupB);
            gPerson1.add(groupC);
            gPerson1.add(groupD);

            gPerson2.add(groupA);
            gPerson2.add(groupB);
            gPerson2.add(groupC);
            gPerson2.add(groupD);

            gPerson3.add(groupA);
            gPerson3.add(groupB);
            gPerson3.add(groupC);
            gPerson3.add(groupD);

            gPerson4.add(groupA);
            gPerson4.add(groupB);
            gPerson4.add(groupC);
            gPerson4.add(groupD);

            //
            // create persistent groups and persons
            //
            db.create(person1);
            db.create(person2);
            db.create(person3);
            db.create(person4);
           
            db.create(groupA);
            db.create(groupB);
            db.create(groupC);
            db.create(groupD);
           
            db.commit();
        } catch (Exception e) {
            log("createTestDataSet: exception caught: " + e.getMessage());
            throw e;
        }
    }
View Full Code Here

        database.close();
    }

    public void testLoadAndUpdateProduct() throws Exception {
        Database database = _category.getDatabase();
       
        database.begin();
        Product product = (Product) database.load(Product.class, new Integer(5));
        database.commit();
       
        assertNotNull(product);
        assertEquals("ctf.jdo.tc9x.Product", product.getClass().getName());
        assertEquals(5, product.getId());
        assertEquals("truck 5", product.getName());
       
        product.setName("truck 5t");

        database.begin();
        database.update(product);
        database.commit();
       
        database.begin();
        product = (Product) database.load(Product.class, new Integer(5));
        database.commit();
       
        assertNotNull(product);
        assertEquals("ctf.jdo.tc9x.Product", product.getClass().getName());
        assertEquals(5, product.getId());
        assertEquals("truck 5t", product.getName());

        product.setName("truck 5");

        database.begin();
        database.update(product);
        database.commit();
       
        database.begin();
        product = (Product) database.load(Product.class, new Integer(5));
        database.commit();

        assertNotNull(product);
        assertEquals("ctf.jdo.tc9x.Product", product.getClass().getName());
        assertEquals(5, product.getId());
        assertEquals("truck 5", product.getName());

        database.close();
    }
View Full Code Here

     * @param groupId primary key of object to be read
     */
    private boolean validReadTransaction(final int groupId,
            final String expectedValue, final boolean checkPeople) {
        log("validating read transaction for group " + groupId + "...");
        Database db = null;
        boolean valid = true;
        try {
            db = this._category.getDatabase();
            db.begin();
            ManyGroup group = (ManyGroup) db.load(ManyGroup.class, new Integer(groupId));
            if (group.getValue1().compareTo(expectedValue) != 0) {
                log("validReadTransaction: value in group " + group.getId()
                        + " does not match expected value, value: " + group.getValue1()
                        + ", expected: " + expectedValue);
                valid = false;
            }
            if (checkPeople) {
                Iterator itor = group.getPeople().iterator();
                while (itor.hasNext()) {
                    ManyPerson person = (ManyPerson) itor.next();
                    if (person.getValue1().compareTo(expectedValue) != 0) {
                        log("validReadTransaction: value in person " + person.getId()
                                + " does not match expected value, value: "
                                + person.getValue1() + ", expected: " + expectedValue);
                        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("validReadTransaction: exception caught while validating read for group "
View Full Code Here

     *
     * @param groupId primary key of object to be updated
     */
    private boolean validWriteTransaction(final int groupId) {
        log("validating write transaction for group " + groupId + "...");
        Database db = null;
        try {
            db = this._category.getDatabase();
            db.begin();
            ManyGroup group = (ManyGroup) db.load(ManyGroup.class, new Integer(groupId));
            group.setValue1(JDO_UPDATED_VALUE);
            Iterator itor = group.getPeople().iterator();
            while (itor.hasNext()) {
                ManyPerson person = (ManyPerson) itor.next();
                person.setValue1(JDO_UPDATED_VALUE);
            }
            db.commit();
            db.close();
        } catch (Exception e) {
            if (db != null) {
                try {
                    db.close();
                } catch (Exception se) {
                    LOG.warn("Problem closing Database instance.", se);
                }
            }
            log("validWriteTransaction: exception caught while validating group write "
View Full Code Here

    private void deleteTestDataSet() {
        log("deleting test data set...");
        QueryResults enumeration;
        ManyGroup group = null;
        ManyPerson person = null;
        Database db = null;
        try {
            // select an group and delete it, if it exist!
            db = this._category.getDatabase();
            db.begin();
            OQLQuery oqlclean = db.getOQLQuery(
                    "SELECT object FROM " + ManyGroup.class.getName()
                    + " object WHERE object.id < $1");
            oqlclean.bind(Integer.MAX_VALUE);
            enumeration = oqlclean.execute();
            while (enumeration.hasMore()) {
                group = (ManyGroup) enumeration.next();
                _stream.println("Retrieved object: " + group);
                db.remove(group);
                _stream.println("Deleted object: " + group);
            }
            db.commit();

            db.begin();
            oqlclean = db.getOQLQuery(
                    "SELECT object FROM " + ManyPerson.class.getName()
                    + " object WHERE object.id < $1");
            oqlclean.bind(Integer.MAX_VALUE);
            enumeration = oqlclean.execute();
            while (enumeration.hasMore()) {
                person = (ManyPerson) enumeration.next();
                _stream.println("Retrieved object: " + person);
                db.remove(person);
                _stream.println("Deleted object: " + person);
            }
            db.commit();
        } catch (Exception e) {
            if (db != null) {
                try {
                    db.close();
                } catch (Exception se) {
                    LOG.warn("Problem closing Database instance.", se);
                }
            }
            log("deleteTestDataSet: exception caught: " + e.getMessage(), e);
View Full Code Here

    public void runTest() throws Exception {
        testCreateAndLoadLaptop();
    }

    public void testCreateAndLoadLaptop() throws Exception {
        Database database = null;
       
        database = _category.getDatabase();
       
        database.begin();
        ProductDetail detail = new ProductDetail();
        detail.setId(10);
        detail.setCategory("category 10");
        detail.setLocation("location 10");
        database.create(detail);
        database.commit();
       
        database.begin();
        LaptopKeyGen laptop = new LaptopKeyGen();
        laptop.setName("laptop 10");
        laptop.setCpu("centrino");
        laptop.setResolution("1600");
        laptop.setWeight(2750);
        laptop.setDetail((ProductDetail)
                database.load(ProductDetail.class, new Integer (10)));
        database.create(laptop);
        database.commit();
       
        int laptopId = laptop.getId();
       
        database.begin();
        laptop = (LaptopKeyGen)
                database.load(LaptopKeyGen.class, new Integer(laptopId));
        database.commit();
       
        assertNotNull(laptop);
        assertEquals("ctf.jdo.tc9x.LaptopKeyGen", laptop.getClass().getName());
        assertEquals(laptopId, laptop.getId());
        assertEquals("laptop 10", laptop.getName());
       
        database.begin();
        database.remove(database.load(LaptopKeyGen.class, new Integer(laptopId)));
        database.commit();
       
        database.begin();
        try {
            laptop = (LaptopKeyGen)
                    database.load(LaptopKeyGen.class, new Integer(laptopId));
            fail("Laptop with id " + laptopId + " still exists.");
        } catch (ObjectNotFoundException e) {
            assertTrue("The object of type ctf.jdo.tc9x.Laptop with identity " + laptopId
                     + " was not found in persistent storage", true);
        }
       
        database.commit();
        database.close();
    }
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.