db4o 7.4

com.db4o.osgi
Interface Db4oService


public interface Db4oService

This API is registered as an OSGi service by the db4o_osgi bundle. It can be accessed like this:

ServiceReference serviceRef = _context.getServiceReference(Db4oService.class.getName()); Db4oService db4oService = (Db4oService)bundleContext.getService(serviceRef);
Configuration config = db4oService.newConfiguration();
// ...
ObjectContainer database = db4oService.openFile(config,fileName);


Subsequently, the database reference can be handled like any other db4o instance.

The main purpose of this service is to configure an OSGi bundle aware reflector for the database instance, so classes that are owned by the client bundle are accessible to the db4o engine. To emulate this behavior when using db4o directly through the exported packages of the db4o_osgi plugin, db4o can be configured like this:

Configuration config = Db4o.newConfiguration();
config.reflectWith(new JdkReflector(SomeData.class.getClassLoader()));
// ...
ObjectContainer database = Db4o.openFile(config,fileName);


Access through the service is recommended over direct usage, though, as the service may implement further OSGi specific features in the future.

See Also:
Db4o, Reflector, "org.osgi.framework.BundleContext"

Method Summary
 com.db4o.config.Configuration newConfiguration()
          Creates a fresh Configuration instance.
 com.db4o.ObjectContainer openClient(com.db4o.config.Configuration config, java.lang.String hostName, int port, java.lang.String user, java.lang.String password)
          opens an ObjectContainer client and connects it to the specified named server and port.
 com.db4o.ObjectContainer openClient(java.lang.String hostName, int port, java.lang.String user, java.lang.String password)
          Operates just like Db4o.openClient(Configuration, String, int, String, String), but uses a newly created, vanilla Configuration context.
 com.db4o.ObjectContainer openFile(com.db4o.config.Configuration config, java.lang.String databaseFileName)
          opens an ObjectContainer on the specified database file for local use.
 com.db4o.ObjectContainer openFile(java.lang.String databaseFileName)
          Operates just like Db4o.openFile(Configuration, String), but uses a newly created, vanilla Configuration context.
 com.db4o.ObjectServer openServer(com.db4o.config.Configuration config, java.lang.String databaseFileName, int port)
          opens an ObjectServer on the specified database file and port.
 com.db4o.ObjectServer openServer(java.lang.String databaseFileName, int port)
          Operates just like Db4o.openServer(Configuration, String, int), but uses a newly created, vanilla Configuration context.
 

Method Detail

newConfiguration

com.db4o.config.Configuration newConfiguration()
Creates a fresh Configuration instance.

Returns:
a fresh, independent configuration with all options set to their default values

openClient

com.db4o.ObjectContainer openClient(java.lang.String hostName,
                                    int port,
                                    java.lang.String user,
                                    java.lang.String password)
                                    throws com.db4o.ext.Db4oException
Operates just like Db4o.openClient(Configuration, String, int, String, String), but uses a newly created, vanilla Configuration context. opens an ObjectContainer client and connects it to the specified named server and port.

The server needs to allow access for the specified user and password.

A client ObjectContainer can be cast to ExtClient to use extended ExtObjectContainer and ExtClient methods.

Parameters:
hostName - the host name
port - the port the server is using
user - the user name
password - the user password
Returns:
an open ObjectContainer
Throws:
com.db4o.ext.Db4oException
See Also:
ObjectServer.grantAccess(java.lang.String, java.lang.String)

openClient

com.db4o.ObjectContainer openClient(com.db4o.config.Configuration config,
                                    java.lang.String hostName,
                                    int port,
                                    java.lang.String user,
                                    java.lang.String password)
                                    throws com.db4o.ext.Db4oException
opens an ObjectContainer client and connects it to the specified named server and port.

The server needs to allow access for the specified user and password.

A client ObjectContainer can be cast to ExtClient to use extended ExtObjectContainer and ExtClient methods.

Parameters:
config - a custom Configuration instance to be obtained via Db4o.newConfiguration()
hostName - the host name
port - the port the server is using
user - the user name
password - the user password
Returns:
an open ObjectContainer
Throws:
com.db4o.ext.Db4oException
See Also:
ObjectServer.grantAccess(java.lang.String, java.lang.String)

openFile

com.db4o.ObjectContainer openFile(java.lang.String databaseFileName)
                                  throws com.db4o.ext.Db4oException
Operates just like Db4o.openFile(Configuration, String), but uses a newly created, vanilla Configuration context. opens an ObjectContainer on the specified database file for local use.

A database file can only be opened once, subsequent attempts to open another ObjectContainer against the same file will result in a DatabaseFileLockedException.

Database files can only be accessed for readwrite access from one process (one Java VM) at one time. All versions except for db4o mobile edition use an internal mechanism to lock the database file for other processes.

Parameters:
databaseFileName - an absolute or relative path to the database file
Returns:
an open ObjectContainer
Throws:
com.db4o.ext.Db4oException
See Also:
Configuration.readOnly(boolean), Configuration.encrypt(boolean), Configuration.password(java.lang.String)

openFile

com.db4o.ObjectContainer openFile(com.db4o.config.Configuration config,
                                  java.lang.String databaseFileName)
                                  throws com.db4o.ext.Db4oException
opens an ObjectContainer on the specified database file for local use.

A database file can only be opened once, subsequent attempts to open another ObjectContainer against the same file will result in a DatabaseFileLockedException.

Database files can only be accessed for readwrite access from one process (one Java VM) at one time. All versions except for db4o mobile edition use an internal mechanism to lock the database file for other processes.

Parameters:
config - a custom Configuration instance to be obtained via Db4o.newConfiguration()
databaseFileName - an absolute or relative path to the database file
Returns:
an open ObjectContainer
Throws:
com.db4o.ext.Db4oException
See Also:
Configuration.readOnly(boolean), Configuration.encrypt(boolean), Configuration.password(java.lang.String)

openServer

com.db4o.ObjectServer openServer(java.lang.String databaseFileName,
                                 int port)
                                 throws com.db4o.ext.Db4oException
Operates just like Db4o.openServer(Configuration, String, int), but uses a newly created, vanilla Configuration context. opens an ObjectServer on the specified database file and port.

If the server does not need to listen on a port because it will only be used in embedded mode with ObjectServer.openClient(), specify '0' as the port number.

Parameters:
databaseFileName - an absolute or relative path to the database file
port - the port to be used, or 0, if the server should not open a port, because it will only be used with ObjectServer.openClient()
Returns:
an ObjectServer listening on the specified port.
Throws:
com.db4o.ext.Db4oException
See Also:
Configuration.readOnly(boolean), Configuration.encrypt(boolean), Configuration.password(java.lang.String)

openServer

com.db4o.ObjectServer openServer(com.db4o.config.Configuration config,
                                 java.lang.String databaseFileName,
                                 int port)
                                 throws com.db4o.ext.Db4oException
opens an ObjectServer on the specified database file and port.

If the server does not need to listen on a port because it will only be used in embedded mode with ObjectServer.openClient(), specify '0' as the port number.

Parameters:
config - a custom Configuration instance to be obtained via Db4o.newConfiguration()
databaseFileName - an absolute or relative path to the database file
port - the port to be used, or 0, if the server should not open a port, because it will only be used with ObjectServer.openClient()
Returns:
an ObjectServer listening on the specified port.
Throws:
com.db4o.ext.Db4oException
See Also:
Configuration.readOnly(boolean), Configuration.encrypt(boolean), Configuration.password(java.lang.String)

db4o 7.4

Copyright 2007 db4objects Inc. All rights reserved.