Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stellation-res] Firebird port

Hi,

FirebirdDatabase.java contains the code to create and manage a
repository using Firebird or InterBase with InterClient as JDBC driver.

Patch1 fixes a problem in LocalHandle.java about passing parameters in a
prepared statement.

Patch2 adds "firebird" as a supported database in Stellation.

This is just the beginning. It seems that there is some not portable SQL
code somewhere else in Stellation that must be found.

There is a type 4 JDBC driver under development at firebirdSQL.org , but
it has a small problem of compatibility with Stellation logging. Once I
make sure that InterClient works 100% I will provide the code to switch
JDBC driver.

Regards,

Rodolfo

-- 

 MAXPROGRAMS
 IBM Business Partner
 Microsoft MSDN Business Connection Partner
 rmraya@xxxxxxxxxxxxxxx
 http://www.maxprograms.com

Index: LocalHandle.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/LocalHandle.java,v
retrieving revision 1.11
diff -u -r1.11 LocalHandle.java
--- LocalHandle.java	1 Sep 2002 18:56:36 -0000	1.11
+++ LocalHandle.java	2 Sep 2002 14:38:04 -0000
@@ -565,17 +565,14 @@
 				_counterManager.createCounter("AV:" + rootID);
 				String statement =
 					"INSERT INTO s_Artifacts (s_id, s_creator, s_type, s_time)"
-						+ " VALUES ("
-						+ rootID
-						+ ", "
-						+ _userid
-						+ ", "
-						+ _db.quoteString(Artifact.Type.COMPOUND) +","
-						+ new Date().getTime()
-						+ ")";
+						+ " VALUES (?,?,?,?) ";
 				// Now, create the initial empty root object.
 				PreparedStatement stmt =
 					_db.getPreparedStatement(statement);
+				stmt.setInt(1, rootID);
+				stmt.setInt(2, _userid);
+				stmt.setString(3, _db.quoteString(Artifact.Type.COMPOUND) );
+				stmt.setLong(4, new Date().getTime() );
 				stmt.executeUpdate(statement);
 				if (desc == null)
 					desc = "";
Index: AbstractDBAccessPoint.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/database/AbstractDBAccessPoint.java,v
retrieving revision 1.3
diff -u -r1.3 AbstractDBAccessPoint.java
--- AbstractDBAccessPoint.java	1 Sep 2002 18:56:36 -0000	1.3
+++ AbstractDBAccessPoint.java	2 Sep 2002 14:38:50 -0000
@@ -57,6 +57,9 @@
         if (_dbkind.equals("postgres")) {
             _db = new PostgresDatabase(this, location);
         }
+        if (_dbkind.equals("firebird")) {
+        	_db = new FirebirdDatabase(this, location);
+        }
     }
             
 
@@ -431,7 +434,7 @@
     
     protected AbstractDatabase _db;
     
-    static final String[] _supportedDBs = new String[] { "postgres", "db2", "oracle" };
+    static final String[] _supportedDBs = new String[] { "postgres", "db2", "oracle", "firebird" };
 
     static final Logger logger = Logger.getLogger(AbstractDBAccessPoint.class);
 
/**
 * @author mxprgrms
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
package org.eclipse.stellation.repos.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;

import org.apache.log4j.Logger;
import org.eclipse.stellation.util.StringList;
import org.eclipse.stellation.util.StringMap;

public class FirebirdDatabase extends BasicDatabase {

    /**
     * Constructor for FirebirdDatabase.
     * @param ap
     * @param location
     * @throws DatabaseException
     */
    public FirebirdDatabase(AbstractDBAccessPoint ap, StringList location)
        throws DatabaseException {
        super(ap, location);

        _dbname = location.remove(0);

        for (int i = 0; i < location.size(); i++) {
            System.out.println(location.get(i));
        }

        ap.setName(_dbname);
        connectToDatabase(_dbname, location);
    }

    /**
     * @see org.eclipse.stellation.repos.database.AbstractDatabase#connectToDatabase(String, StringMap)
     */
    public void connectToDatabase(String locationSpec, StringList options)
        throws DatabaseException {
        try {

			/*
			 *TODO 
			 *  
			 * The following parameters are standard values
			 * for Interbase/Firebird databses
			 * 
			 * There should be a mechanism to change these
			 * defaults at runtime, via options or something 
			 * similar
			 */

            String host = "localhost";
            String port = "3060";
            String user = "sysdba";
            String pass = "masterkey";

            String url =
                "jdbc:interbase://" + host + ":" + port + "/" + _dbname;
            
            Class.forName("interbase.interclient.Driver");
            _conn = DriverManager.getConnection(url, user, pass);
            initializeDatabase(_conn);

        } catch (ClassNotFoundException e) {
            throw new DatabaseConnectionException(
                getAccessPoint(),
                "Could not load InterClient JDBC driver for Firebird ");
        } catch (SQLException sqe) {
            throw new DatabaseConnectionException(
                getAccessPoint(),
                "Error connecting to database server " + sqe);
        }
    }

    /**
     * Method createTable.
     * @param table
     * @throws DatabaseException
     * 
     * This method overrides BasicDatabase#createTable making it a lot simpler.
     */
    public void createTable(Table table) throws DatabaseException {
        try {
            _stmt.execute(table.generateSQL());
        } catch (SQLException sqle) {
            throw new DatabaseConnectionException(
                getAccessPoint(),
                "Error creating table " + sqle);
        }
    }

    /**
     * @see org.eclipse.stellation.repos.database.AbstractDatabase#getBlobType()
     */
    public String getBlobType() {
        return "BLOB";
    }

    /**
     * @see org.eclipse.stellation.repos.database.AbstractDatabase#getClobType()
     */
    public String getClobType() {
        return "BLOB SUBTYPE TEXT";
    }

    /**
     * @see org.eclipse.stellation.repos.database.AbstractDatabase#getTimeType()
     */

    public String getTimeType() {
        /*
         * The right data type should be TIMESTAMP
         * 
         * DOUBLE PRECISION is used because there is code that
         * manage time values as long integers, longer than the 
         * INTEGER type suported by Firebird.
         * 
         * At org.eclipse.stellation.repos.LocalHandle there is code that reads
         * 	stmt.setLong(4, new Date().getTime() );
         * 
         * instead of 
         *     stmt.setDate(4, new Date() );
         * 
         * Date type provides millisencond precisicion. 
         * If we get paranoid, we can also use TimeStamp()
         * for theorical nanosecond precision.
         * 
         */
        return "DOUBLE PRECISION";
    }

    public String getLongStringType() {
        return "VARCHAR(4000)";
    }

    public int getLongStringLength() {
        return 4000;
    }

    /**
     * @see org.eclipse.stellation.repos.database.AbstractDatabase#getShortStringLength()
     */
    public int getShortStringLength() {
        /*
         * Firebird supports key lenghts up to 253 bytes
         * 
         * There is a compound primary key in a table
         * defined as (INTEGER, INTEGER, VARCHAR(255) )
         * that forces the reduction to 180 to fit in the maximun
         * key lenght
         * 
         */
        return 180;
    }

    protected String _dbname;
    protected String _host;
    protected String _port;

    static final Logger logger = Logger.getLogger(FirebirdDatabase.class);

}

Back to the top