[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ozone &servlets




Hello,

I tried turning the tutorial example to a servlet. I use Tomcat,
I added the ozoneEnv in the tomcat startup script and everything should
be fine
but, when I run the servlet the connection is opened and closed ok but
the
create , print and delete does not work.
In a new Db (ozoneInst)
the create Car throws Exception Error: CarImpl_Proxy
the print Error:null and
the Delete Error:null.
the second time the servlet is called
the create throws Error:Root object name 'my_first_car' already exists
????
the print Error:CarImpl_Proxy and
the delete Error:null.
It seems to me that ozone can not decide whether it has created the
object or not,
if the object is in the Db or not etc.

can anybody understand what is going on ????


import org.ozoneDB.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class MyApp extends HttpServlet {

    private static ExternalDatabase db;

    public void doGet( HttpServletRequest req, HttpServletResponse res )

    throws ServletException, IOException
    // main( String[] args ) throws Exception
    {

       res.setContentType("text/html");

       ServletOutputStream out = res.getOutputStream();


out.println("<HTML><HEAD><TITLE>TEST</TITLE></HEAD><BODY>Hello</BODY>");

            createDb();

            createCar();

            printCar(out);

            deleteCar();


            closeDb();

    }

    public static void createDb()
    {
        try{
        // create and open a new database connection
        db = ExternalDatabase.openDatabase(
"ozonedb:remote://localhost:3333" );
        System.out.println( "Connected ..." );
        System.out.println( "Reloading ..." );
        db.reloadClasses();
        }catch( Exception e)
        {
          System.out.println("Could not open Ozone !!!");
          System.out.println("Error :"+e.getMessage());
        }
    }

    public static void createCar() {
        try{
        // create a new Car object with the name "my_first_car"
        // the return value is Car_proxy, which implements the
Car-interface
        System.out.println( "Create object ..." );
        Car car = (Car)(db.createObject( CarImpl.class.getName(), 0,
                "my_first_car" ));
        System.out.println( "Set values ..." );
        car.setName( "gottfried" );
        car.setYearOfConst( 1957 );
        }catch( Exception e)
        {
          System.out.println("Could not Create Object in Ozone !!");
          System.out.println("Error :"+e.getMessage());
        }


    }

    public static void printCar(ServletOutputStream out) {
        try{
        System.out.println( "Print ..." );
        Car car = (Car)(db.objectForName( "my_first_car" ));
        if (car != null) {
            out.println( "The car " + car.name() + " is "
                    + car.age() + " years old." );
        } else {
            out.println( "Object my_first_car not found." );
        }
        }catch( Exception e)
        {
          System.out.println("Can not print !!");
          System.out.println("Error :"+e.getMessage());
        }
    }

    public static void deleteCar()  {
        try{
        System.out.println( "Delete ..." );
        Car car = (Car)(db.objectForName( "my_first_car" ));
        if (car != null) {
            db.deleteObject( car );
        } else {
            System.out.println( "Object my_first_car not found." );
        }
        }catch( Exception e)
        {
          System.out.println("Could not delete object in Ozone !!");
          System.out.println("Error :"+e.getMessage());
        }
    }

    public static void closeDb()
    {
      try{
            System.out.println( "Close ..." );
            db.close();
            }catch( Exception e )
            {
             System.out.println("Could not close Ozone !!");
             System.out.println("Error :"+e.getMessage());
            }
    }

     public String getServletInfo() {
        return "Ozone-Servlet test";
     }


}