Home > Object Persistency API > API Reference > Connect to a Database
First of all you need to connect to an existing database or to create a new one.
Please note: this is the only one section where different back-end implementations lead to a slightly different API. The result of each method presented here is of type EOContainer which provides the standard interface of an entity object container. That interface and every interface that can be reached from there is totally independent of the underlying implementations.
NetworkEOC
The NetworkEOC is used for connecting to a remote server via OOMEGA's Network Layer which is a middleware that delegates your database queries and object interactions to a remote database - and it offers the very same API as every other persistency back-end. Finally, at the server side, VersantEOC or HibernateEOC is used to interact with the database.
The getOpenModelsEOC methods can be used to connect to the open metamodel repository at http://www.open-models.org.
package org.oomega.network.client; public class NetworkEOC extends TransactionalEOC<NetworkEOCSession> { public static NetworkEOC getEOC(InetAddress serverAddress, int serverPort, int preloadDepth); public static NetworkEOC getEOC(InetAddress serverAddress); public static NetworkEOC getOpenModelsEOC(); public static NetworkEOC getOpenModelsEOC(int preloadDepth);
VersantEOC
The VersantEOC is meant to connect to Versant Object Database. It should be used locally on the server - please refer to the NetworkEOC for communication between client and server.
Please note the long... pids parameter of the createEOC method. The size of the array is equal to the maximum amount of concurrent sessions and the provided producer identifiers (PIDs) will become part of object identifiers (OIDs).
package net.oomega.versant; public class VersantEOC extends AbstractEOC<VersantEOCSession> { public static VersantEOC createEOC(InetAddress host, String dbName, String user, String password, long... pids); public static VersantEOC getEOC(InetAddress host, String dbName, String user, String password); }
HibernateEOC
The HibernateEOC is meant to connect to a relational database via Hibernate. It should be used locally on the server - please refer to the NetworkEOC for communication between client and server.
Please note the long... pids parameter of the createEOC method. The size of the array is equal to the maximum amount of concurrent sessions and the provided producer identifiers (PIDs) will become part of object identifiers (OIDs).
package net.oomega.hibernate; public class HibernateEOC extends AbstractEOC<HibernateEOCSession> { public static HibernateEOC createEOC(Class jdbcDriverClass, Class dialect, String url, String user, String password, long... pids); public static HibernateEOC getEOC(Class jdbcDriverClass, Class dialect, String url, String user, String password); }
Db4objectsEOC
The Db4objectsEOC is meant to connect to the ODBMS db4objects. db4o shouldn't be used on the server as the support for concurrent users is not that good.
package net.oomega.db4bobjects; public class Db4objectsEOC extends AbstractEOC<Db4objectsEOCSession> { public static Db4objectsEOC createEOC(File dbfile, long... pids); public static Db4objectsEOC getEOC(File dbfile); }
FileEOC
The FileEOC is a single-user in-memory database. In fact it's relying on the MemoryEOC implementation, but the database contents are persisted to a file.
package org.oomega.persistence; public class FileEOC<SESSION_TYPE extends FileEOCSession> extends MemoryEOC<SESSION_TYPE> { public static FileEOC createEOC(File dbfile, long... pids); public static FileEOC getEOC(File dbfile); }
MemoryEOC
The MemoryEOC is a single-user in-memory database. In contrast to the FileEOC the database contents are really transient.
package org.oomega.persistence; public class MemoryEOC<SESSION_TYPE extends MemoryEOCSession> extends AbstractEOC<SESSION_TYPE> { public static MemoryEOC createEOC(long... pids); }
Next chapter: Obtain a Session