root/trunk/corelib/src/org/bridgedb/rdb/DBConnector.java @ 106

Revision 106, 3.8 KB (checked in by martijn, 14 months ago)

Fixed style and javadoc issues

Line 
1// BridgeDb,
2// An abstraction layer for identifer mapping services, both local and online.
3// Copyright 2006-2009 BridgeDb developers
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17package org.bridgedb.rdb;
18
19import java.sql.Connection;
20import java.sql.SQLException;
21
22import org.bridgedb.IDMapperException;
23
24
25/**
26 * DBConnector is used by SimpleGex and SimpleGdb
27 * to perform operations
28 * such as creating a new database
29 * or establishing a connection
30 * that are different for Derby, Hsqldb, etc.
31 *
32 * This class implements only non-GUI functionality.
33 * There is a derived DBConnSwt class that also
34 * includes dialogs to set the parameters
35 * for opening / creating.
36 */
37public abstract class DBConnector
38{
39        public static final int PROP_NONE = 0;
40        public static final int PROP_RECREATE = 4;
41        public static final int PROP_FINALIZE = 8;
42       
43        /**
44         * Type for gene database.
45         */
46        public static final int TYPE_GDB = 0;
47        /**
48         * Type for expression database.
49         */
50        public static final int TYPE_GEX = 1;
51
52        public abstract Connection createConnection(String dbName, int props) throws IDMapperException;
53       
54        /**
55         * Close the given connection.
56         * @param con The connection to be closed
57         * @throws IDMapperException when there was a database error
58         */
59        public void closeConnection(Connection con) throws IDMapperException
60        {
61                closeConnection(con, PROP_NONE);
62        }
63       
64        /**
65         * Close the given connection, and optionally finalize it after creation (using {@link #PROP_FINALIZE}).
66         * @param con The connection to be closed
67         * @param props Close properties (one of {@link #PROP_NONE}, {@link #PROP_FINALIZE} or {@link #PROP_RECREATE})
68         * @throws IDMapperException when there was a database error
69         */
70        public void closeConnection(Connection con, int props) throws IDMapperException
71        {
72                try
73                {
74                        con.close();
75                }
76                catch (SQLException e)
77                {
78                        throw new IDMapperException (e);
79                }
80        }
81       
82        private int dbType;
83
84        /**
85         * Set the database type (one of {@link #TYPE_GDB} or {@link #TYPE_GEX}).
86         * @param type The type of the database that will be used for this class
87         */
88        public void setDbType(int type) { dbType = type; }
89       
90        /**
91         * Get the database type (one of {@link #TYPE_GDB} or {@link #TYPE_GEX}).
92         * @return The type of the database that is used for this class
93         */
94        public int getDbType() { return dbType; }
95       
96        /**
97         * This method is called to finalize the given database after creation
98         * (e.g. set read-only, archive files). The database name needs to returned, this
99         * may change when finalizing the database modifies the storage type (e.g. from directory
100         * to single file).
101         * The database connection needs to be closed before running this method.
102         * @param dbName The name of the database to finalize   
103         * @return The name of the finalized database
104         * @throws IDMapperException when there was a database error
105         */
106        public abstract String finalizeNewDatabase(String dbName) throws IDMapperException;
107               
108        /**
109         * This method may be implemented when the database files need to be
110         * compacted or defragmented after creation of a new database. It will be called
111         * after all data is added to the database.
112         * @param con A connection to the database
113         * @throws IDMapperException when there was a database error
114         */
115        public void compact(Connection con) throws IDMapperException
116        {
117                //May be implemented by subclasses
118        }
119       
120
121}
Note: See TracBrowser for help on using the browser.