1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db;
14 import java.util.Properties;
16 import org.simantics.db.exception.DatabaseException;
19 * The interface that every driver class must implement.
22 * Each driver should supply a class that implements the Driver interface.
25 * The {@link Manager} will try to load as many drivers as it can find and then
26 * for any given connection request, it will ask each driver in turn to try to
27 * connect to the target URL.
30 * It is strongly recommended that each Driver class should be small and
31 * standalone so that the Driver class can be loaded and queried without
32 * bringing in vast quantities of supporting code.
35 * When a Driver class is loaded, it should create an instance of itself and
36 * register it with the DriverManager. This means that a user can load and
37 * register a driver by calling
40 * <code>Class.forName("foo.bah.Driver")</code>
45 public interface Driver {
47 * Driver name identifies the used database driver.
48 * At any time there can be only one implementation registered for each name.
50 * @return name of the driver instance.
52 public String getName();
54 * @return current database user agent. Can be null.
56 public DatabaseUserAgent getDatabaseUserAgent(String address) throws DatabaseException;
58 * Set user agent to be used by other methods. Can be null.
60 * @param dbUserAgent defines error recover policy. Database specific.
62 public void setDatabaseUserAgent(String address, DatabaseUserAgent dbUserAgent) throws DatabaseException;
64 * Attempts to make a database connection to the given address.
67 * The driver should throw a {@link DatabaseException} if it has trouble
68 * connecting to the database.
71 * The <code>java.util.Properties</code> argument can be used to pass
72 * arbitrary string tag/value pairs as connection arguments. Normally at
73 * least "user" and "password" properties should be included in the
74 * <code>Properties</code> object.
81 * @param address of the database session. Driver implementation specifies the address format.
82 * @param properties a list of arbitrary string tag/value pairs as connection
83 * arguments. Normally at least a "user" and "password" property
85 * @return a <code>Session</code> object that represents a connection to the
87 * @throws DatabaseException TODO: separate possible errors (connection,
88 * authentication, initialization)
90 Session getSession(String address, Properties properties) throws DatabaseException;
93 * Return database server that can be used to control a local database process.
95 * @param address of the database server. Driver implementation specifies the address format.
96 * @param properties a list of arbitrary string tag/value pairs as connection
97 * arguments. Normally at least a "user" and "password" property
100 * @throws DatabaseException
102 ServerI getServer(String address, Properties properties) throws DatabaseException;
105 * Return database management object that can be used to control a local database.
107 * @param address of the database. Driver implementation specifies the address format.
108 * @param properties a list of arbitrary string tag/value pairs as connection
109 * arguments. Normally at least a "user" and "password" property
110 * should be included.
111 * @return Management object for controlling database.
112 * @throws DatabaseException
114 Management getManagement(String address, Properties properties) throws DatabaseException;
116 interface Management {
118 * Existence of database means that the database has been created.
120 * @return true if database exist.
122 * @throws DatabaseException
124 public boolean exist() throws DatabaseException;
126 * Delete's database. After this {@link #exist()} must return false.
128 * @throws DatabaseException if database deletion failed.
129 * This may leave the database in an inconsistent state.
130 * Recovery from this is implementation specific.
132 public void delete() throws DatabaseException;
134 * Creates a new database. After this {@link #exist()} must return false.
136 * @throws DatabaseException if database creation failed.
137 * This may leave the database in an inconsistent state.
138 * Recovery from this is implementation specific.
140 public void create() throws DatabaseException;
142 * Removes caching data leaving only persistent data.
144 * @throws DatabaseException
146 public void purge() throws DatabaseException;
147 public void shutdown() throws DatabaseException;