Package org.apache.ojb.odmg

Source Code of org.apache.ojb.odmg.AutoIncrementWithRelatedObjectTest

/**
* Author: Matthew Baird
* mattbaird@yahoo.com
*/
package org.apache.ojb.odmg;

import junit.framework.TestCase;
import org.apache.ojb.broker.Table_1Object;
import org.apache.ojb.broker.Table_2Object;
import org.apache.ojb.broker.TestHelper;
import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.Transaction;

/**
* @author MBaird mattbaird@yahoo.com
* Equivalent to the PB test of the same name, but redone using ODMG api.
*
* works for HSQLDB
* fails for MSSQL :(
*
* @see org.apache.ojb.broker.AutoIncrementWithRelatedObjectTest
*/
public class AutoIncrementWithRelatedObjectTest extends TestCase
{
    private static Class CLASS = AutoIncrementWithRelatedObjectTest.class;
    private String databaseName;

    public static void main(String[] args)
    {
        String[] arr = {CLASS.getName()};
        junit.textui.TestRunner.main(arr);
    }

    /**
     * since java defaults the value of an int to 0, there might be a problem storing an
     * object that uses int's as foreign keys. If this doesn't work, it means we can't use int's
     * as foreign keys in ODMG. :(
     */
    public void testCreateWithoutRelatedObject() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            Table_1Object table1Ojb = new Table_1Object();
            db.makePersistent(table1Ojb);
            tx.commit();
        }
        finally
        {
            db.close();
        }
    }

    /**
     * do the create with a related object to prove it works in ODMG mode.
     */
    public void testCreateWithRelatedObject() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            Table_1Object table1Obj = new Table_1Object();
            Table_2Object table2Obj = new Table_2Object();
            table1Obj.setTable2Object(table2Obj);
            db.makePersistent(table2Obj);
            db.makePersistent(table1Obj);
            tx.commit();
        }
        finally
        {
            db.close();
        }
    }

    /**
     * Insert the method's description here.
     * Creation date: (24.12.2000 00:33:40)
     */
    public AutoIncrementWithRelatedObjectTest(String name)
    {
        super(name);
    }

    /**
     * Insert the method's description here.
     * Creation date: (06.12.2000 21:58:53)
     */
    public void setUp()
    {
        databaseName = TestHelper.DEF_DATABASE_NAME;
    }

    /**
     * Insert the method's description here.
     * Creation date: (06.12.2000 21:59:14)
     */
    public void tearDown()
    {
    }
}
TOP

Related Classes of org.apache.ojb.odmg.AutoIncrementWithRelatedObjectTest

TOP
Copyright © 2018 www.massapi.com. 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.