Package org.odmg

Examples of org.odmg.Implementation


     *
     * @param product The product to store
     */
    public static void storeProduct(Product product)
    {
        Implementation impl = OJB.getInstance();
        Transaction    tx   = impl.newTransaction();

        tx.begin();
        tx.lock(product, Transaction.WRITE);
        tx.commit();
    }
View Full Code Here


     * @param name The name of the product
     * @return The product if found
     */
    public static Product findProductByName(String name) throws Exception
    {
        Implementation impl = OJB.getInstance();
        Transaction    tx   = impl.newTransaction();

        tx.begin();

        OQLQuery query = impl.newOQLQuery();

        query.create("select products from " + Product.class.getName() + " where name = $1");
        query.bind(name);

        DList   results = (DList)query.execute();
View Full Code Here

     * @param product The product to sell
     * @param number  The number of items to sell
     */
    public static void sellProduct(Product product, int number)
    {
        Implementation impl = OJB.getInstance();
        Transaction    tx   = impl.newTransaction();

        tx.begin();

        tx.lock(product, Transaction.WRITE);
        product.setStock(product.getStock() -  number);
View Full Code Here

     *
     * @param product The product to delete
     */
    public static void deleteProduct(Product product)
    {
        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 product The product to update in the database
     */
    public static void persistChanges(Product product)
    {
        Implementation impl = OJB.getInstance();
        TransactionExt tx  = (TransactionExt)impl.newTransaction();

        tx.begin();
        tx.markDirty(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();

View Full Code Here

     * Creates a new application object.
     */
    public Application()
    {
        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database       db   = odmg.newDatabase();

        // open database
        try
        {
            db.open(databaseName, Database.OPEN_READ_WRITE);
View Full Code Here

    public void testBind() throws Exception
    {
        String bindingName = "binding_for_testBind";

        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);
        // clean up roots map
        clearNRM();

        Article example = createArticle();

        Transaction tx = odmg.newTransaction();
        tx.begin();
        try
        {
            db.bind(example, bindingName);
            Article value = (Article) db.lookup(bindingName);
View Full Code Here

    {
        String bindingName = "binding_for_testDoubleBindInOneTx";

        DList foundList = null;
        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        //open database
        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        tx.begin();
        db.bind(odmg.newDList(), bindingName);

        foundList = (DList)db.lookup(bindingName);
        assertTrue("Could not found bound DList", foundList != null);
        foundList = null;

        db.unbind(bindingName);
        try
        {
            foundList = (DList) db.lookup(bindingName);
            fail("Found unbound DList");
        }
        catch (ObjectNameNotFoundException ex)
        {
        }

        db.bind(odmg.newDList(), bindingName);
        try
        {
            foundList = (DList) db.lookup(bindingName);
        }
        catch (ObjectNameNotFoundException ex)
        {
            fail("Could not found bound DList, binding name was: "+bindingName);
        }
        foundList = null;
        tx.commit();

        tx = odmg.newTransaction();
        tx.begin();
        try
        {
            DList newList = (DList)db.lookup(bindingName);
            db.unbind(bindingName);
View Full Code Here

    public void testLookup() throws Exception
    {
        String bindingName = "binding_for_testLookup";
        // get facade instance
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);

        // clear named roots.
        clearNRM();
        Transaction tx = odmg.newTransaction();
        //bind object to name
        tx.begin();
        Article example = createArticle();
        Identity oid = new Identity(example, ((HasBroker)tx).getBroker());

        try
        {
            db.bind(example, bindingName);
            tx.commit();
        }
        catch (ObjectNameNotUniqueException ex)
        {
            tx.abort();
            fail(ex.getMessage());
        }

        // TestThreadsNLocks look up
        Article lookedUp1 = null;
        tx = odmg.newTransaction();
        tx.begin();

        try
        {
            // lookup by name binding
View Full Code Here

TOP

Related Classes of org.odmg.Implementation

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.