Package org.ozoneDB.odmg

Source Code of org.ozoneDB.odmg.OzoneServerODMGDatabase

// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by softwarebuero m&b (SMB).
//
// The original code and portions created by SMB are
// Copyright (C) 1997-1999 by softwarebuero m&b (SMB). All rights reserved.
//
// $Id: OzoneServerODMGDatabase.java,v 1.1 2002/05/08 15:03:21 per_nyfelt Exp $

package org.ozoneDB.odmg;

import java.util.*;
import org.odmg.*;
import org.ozoneDB.OzoneInterface;
import org.ozoneDB.ExternalDatabase;
import org.ozoneDB.LocalDatabase;
import org.ozoneDB.RemoteDatabase;
import org.ozoneDB.OzoneProxy;
import org.ozoneDB.OzoneRemote;
import org.ozoneDB.OzoneCompatible;


/**
* Implementation of the ODMG {@link org.odmg.Database} interface that is used
* inside the ozone server to give the ODMG database objects their environment
* and their interface to the database.
*
*
* @author <a href="http://www.softwarebuero.de/">SMB</a>
* @version $Revision: 1.1 $Date: 2002/05/08 15:03:21 $
*/
public class OzoneServerODMGDatabase implements EnhDatabase {
   
    private int accessMode = OPEN_READ_WRITE;
   
    private org.ozoneDB.core.Env env;
   
   
    public OzoneServerODMGDatabase() {
        env = org.ozoneDB.core.Env.currentEnv();
    }
   
   
    protected int mode() {
        return accessMode;
    }
   
   
    /**
     * Open this ODMG database.
     * @param _url URL of the database (ozonedb:remote://host:port or ozonedb:local://datadir)
     */
    public synchronized void open( String _url, int _accessMode ) throws ODMGException {
        throw new ODMGRuntimeException( "Method must not be called." );
    }
   
   
    public void close() throws ODMGException {
        throw new ODMGRuntimeException( "Method must not be called." );
    }
   
   
    protected void finalize() throws Throwable {
    }
   
   
    public void makePersistent( Object object ) {
        throw new ODMGRuntimeException( "Method must not be called." );
    }
   
   
    public Object createPersistent( Class cl ) {
        if (cl.isAssignableFrom( OzoneCompatible.class )) {
            throw new ClassNotPersistenceCapableException( cl.getName() );
        }
       
        try {
            return env.database.createObject( cl.getName(), OzoneInterface.Public, null );
        } catch (Exception e) {
            throw new ODMGRuntimeException( e.toString() );
        }
    }
   
   
    public void deletePersistent( Object object ) {
        if (!(object instanceof OzoneProxy)) {
            throw new ObjectNotPersistentException( object.getClass().getName() );
        }
       
        try {
            env.database.deleteObject( (OzoneRemote)object );
        } catch (Exception e) {
            throw new ODMGRuntimeException( e.toString() );
        }
    }
   
   
    public void bind( Object object, String name ) {
        if (!(object instanceof OzoneProxy)) {
            throw new ClassNotPersistenceCapableException( object.getClass().getName() );
        }
       
        try {
            env.database.nameObject( (OzoneRemote)object, name );
        } catch (Exception e) {
            throw new ODMGRuntimeException( e.toString() );
        }
    }
   
   
    public void unbind( String name ) throws ObjectNameNotFoundException {
        try {
            Object obj = lookup( name );
            if (obj != null) {
                env.database.nameObject( (OzoneRemote)obj, null );
            }
        } catch (Exception e) {
            throw new ODMGRuntimeException( e.toString() );
        }
    }
   
   
    public Object lookup( String name ) throws ObjectNameNotFoundException {
        Object result = null;
        try {
            result = env.database.objectForName( name );
        } catch (Exception e) {
            throw new ODMGRuntimeException( e.toString() );
        }
       
        if (result == null) {
            throw new ObjectNameNotFoundException( name );
        }
       
        return result;
    }
   
   
    public boolean containsObject( Object obj ) {
        if (!(obj instanceof OzoneProxy)) {
            throw new ClassNotPersistenceCapableException( obj.getClass().getName() );
        }
       
        OzoneProxy proxy = (OzoneProxy)obj;
        return proxy.link == env.database;
    }
   
}
TOP

Related Classes of org.ozoneDB.odmg.OzoneServerODMGDatabase

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.