A simple application that creates objects in the database - Java

Click here to view in C++

Connecting to the database.

Connection connection = Connection.open(bootfile, oo.openReadWrite);
//where bootfile is the String value of the path to the bootfile
//and the second arguement is the mode in which to connect

For more information on connections visit our FAQ.



Using a session.

Session session = new Session();
session.begin();           // Start the transaction
...............   		// perform database operations
session.commit();          // Commit the transaction

For more information on sessions visit our FAQ.


Creating a database.

ooDBObj db = fd.newDB(dbName);
//where dbName is the String value of the database name
//and fd is the ooFDObj object

For more information on handles or databases visit our FAQ.


Creating a container.

ooContObj cont = new ooContObj();
db.addContainer(cont, contName, 0, 0, 0);
//where contName is the String value of the container name
//and db is the ooDBObj object

For more information on containers visit our FAQ.


Creating an object.

ooObj obj = new ooObj;
cont.cluster(obj);
//where cont is the ooContObj object where you want to cluster the object

For more information on objects visit our FAQ.



Simple application.

simpleapp.java


import com.objy.db.*;
import com.objy.db.app.*;

public class simpleapp
{
	public static void main(String[] args)
	{
		String bootfile = "test.boot";		//insert bootfile name here
		String dbName = "testDB";		//insert db name here
		String contName = "testCont";		//insert cont name here

		Connection connection = null;
		Session session = null;
		try
		{
			connection = Connection.open(bootfile, oo.openReadWrite);
			connection.loadSchemaClasses(true);
			session = new Session();
			ooFDObj fd = session.getFD();
			session.begin();
			ooDBObj db = null;
			if(fd.hasDB(dbName))
			{
				db = fd.lookupDB(dbName);
			}
			else
			{
				db = fd.newDB(dbName);
			}
			ooContObj cont = null;
			if(db.hasContainer(contName))
			{
				cont = db.lookupContainer(contName);
			}
			else
			{
				cont = new ooContObj();
				db.addContainer(cont, 0, contName, 0, 0);
			}

			ooObj obj = null;
			for (int i = 0; i < 100; i++)
			{
				obj = new ooObj();
				cont.cluster(obj);
			}
			session.commit();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			session.abort();
		}
	}
}