Package org.odmg

Examples of org.odmg.Database


        newProduct.setStock(Integer.parseInt(in));

        // now perform persistence operations

        // 3. open transaction
        Database db = odmg.getDatabase(null); // the current DB
        Transaction tx = odmg.newTransaction();

        tx.begin();

        // 4. make persistent new object
        db.makePersistent(newProduct);

        // 5. commit transaction
        tx.commit();
    }
View Full Code Here


        // get facade instance
        // use one Implementation instance per database
        // it's recommended to share the Implementation and Database instances
        // in the application, instead of always instantiate and open it.
        Implementation odmg = OJB.getInstance();
        Database       db   = odmg.newDatabase();

        // open database
        try
        {
            db.open(DATABASE_NAME, Database.OPEN_READ_WRITE);
        }
        catch (ODMGException ex)
        {
            ex.printStackTrace();
        }
View Full Code Here

        MainObject obj_1 = new MainObject(null, name);
        MainObject obj_2 = new MainObject(null, name);
        MainObject obj_3 = new MainObject(null, name);

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(obj_1, Transaction.WRITE);
        tx.lock(obj_2, Transaction.WRITE);
View Full Code Here

        s_ref_3.setMainObject(obj_1);
        obj_2.setSingleReference(s_ref_4);
        s_ref_3.setMainObject(obj_1);

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        db.makePersistent(s_ref_1);
        db.makePersistent(s_ref_2);
        db.makePersistent(s_ref_3);
        db.makePersistent(s_ref_4);

        db.makePersistent(obj_1);
        db.makePersistent(obj_2);
        tx.commit();

        // try to find both objects
        Criteria crit = new Criteria();
        crit.addEqualTo("name", name);
View Full Code Here

        Implementation impl = OJB.getInstance();
        Transaction    tx = impl.newTransaction();

        tx.begin();

        Database db = impl.getDatabase(product);

        db.deletePersistent(product);

        tx.commit();
    }
View Full Code Here

     * @param args The commandline arguments
     */
    public static void main(String[] args) throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database       db   = odmg.newDatabase();

        db.open("default", Database.OPEN_READ_WRITE);

        Product product = new Product();

        product.setName("Widget");
        product.setPrice(9.99);
        product.setStock(11);

        storeProduct(product);

        Product same = findProductByName(product.getName());

        System.out.println(same.getId() + " = " + product.getId());

        sellProduct(same, 1);

        db.close();
    }
View Full Code Here

     * @see org.apache.avalon.framework.activity.Disposable#dispose()
     */
    public void dispose() {
        final Set keys = this.databases.keySet();
        for (Iterator i = keys.iterator(); i.hasNext();) {
            final Database db = (Database) i.next();
            try {
                db.close();
            } catch (ODMGException e) {
                getLogger().error("OJB-ODMG: Cannot close Database", e);
            }
            i.remove();
        }
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.ODMG#getInstance(java.lang.String, int)
     */
    public Implementation getInstance(String connection, int mode) throws ODMGException {
        synchronized (this.databases) {
            Database db = (Database) this.databases.get(connection + ":" + mode);
            if (null == db) {
                db = this.odmg.newDatabase();
                db.open(connection, mode);
                this.databases.put(connection + ":" + mode, db);
            }
        }
        return this.odmg;
    }
View Full Code Here

        // So first we have to lookup the object.

        // 1. build oql query to select product by id:
        String oqlQuery = "select del from " + Product.class.getName() + " where id = " + id;

        Database    db = odmg.getDatabase(null); // the current DB
        Transaction tx = null;

        try
        {
            // 2. start transaction
            tx = odmg.newTransaction();
            tx.begin();

            // 3. lookup the product specified by query
            OQLQuery query = odmg.newOQLQuery();

            query.create(oqlQuery);

            List   result      = (List)query.execute();
            Product toBeDeleted = (Product)result.get(0);

            // 4. now mark object for deletion
            db.deletePersistent(toBeDeleted);
            // 5. commit transaction
            tx.commit();
        }
        catch (Throwable t)
        {
View Full Code Here

        newProduct.setStock(Integer.parseInt(in));

        // now perform persistence operations

        // 3. open transaction
        Database db = odmg.getDatabase(null); // the current DB
        Transaction tx = odmg.newTransaction();

        tx.begin();

        // 4. make persistent new object
        db.makePersistent(newProduct);

        // 5. commit transaction
        tx.commit();
    }
View Full Code Here

TOP

Related Classes of org.odmg.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.