Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stellation-res] Firebird port w/copyright + more patches

Hi,

Here is another version of the Firebird access point with the copyright
notice included.

Also, here are 5 patches that must be carefully checked. This patches
modify some queries used to retrieve artifacts.

Original queries have the form:

   select s_field1, s_field 2 
   from s_atable AS table 
   where s_field1 = "1"

I deleted the AS keyword because in Firebird/Interbase you can only use
AS with fields, not table names.

Now the queries look like this:

   select s_field1, s_field 2 
   from s_atable table 
   where s_field1 = "1"

I don't know if this will cause troubles with other databases.

Another problem I noticed is the comparison against NULL. 

Current queries have the form:

   select s_field1, s_field 2 
   from s_atable AS table 
   where s_field1 = NULL

and they should be like:

   select s_field1, s_field 2 
   from s_atable table 
   where s_field1 IS NULL

to avoid problems with Firebird/Interbase. 

I have hot found all the places where this happens, so I can't provide
patches yet.Again, I don't know how this will affect other databases.

Regards,

Rodolfo

-- 

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

/*******************************************************************************
 * Copyright (c) 2002 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 * Rodolfo Raya - Initial implementation
 ******************************************************************************/
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 java.sql.ResultSet;


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
         * 
         * NUMERIC(18,0) 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 "NUMERIC(18,0)";
    }

    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;

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

}
Index: RetrievalManager.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/RetrievalManager.java,v
retrieving revision 1.6
diff -u -r1.6 RetrievalManager.java
--- RetrievalManager.java	1 Sep 2002 18:56:36 -0000	1.6
+++ RetrievalManager.java	2 Sep 2002 17:59:24 -0000
@@ -107,8 +107,8 @@
                     + "br.s_id, "
                     + "p.s_rootid "
                     + "FROM "
-                    + "s_Branches as br, "
-                    + "s_Projects as p "
+                    + "s_Branches br, "
+                    + "s_Projects p "
                     + "WHERE "
                     + "p.s_name = '"
                     + branchImage.getProjectName()
@@ -172,8 +172,8 @@
                         + "br.s_name, "
                         + "bh.s_pvid "
                         + "FROM "
-                        + "s_BranchHistory as bh,"
-                        + "s_Branches as br "
+                        + "s_BranchHistory bh,"
+                        + "s_Branches br "
                         + "WHERE "
                         + "bh.s_parent = br.s_id"
                         + " AND bh.s_branch = "  + branchID
@@ -205,7 +205,7 @@
                         + "bc.s_aid, "
                         + "bc.s_exec "
                         + "FROM "
-                        + "s_BranchContents as bc "
+                        + "s_BranchContents bc "
                         + "WHERE "
                         + "bc.s_branch = "
                         + branchID
@@ -251,8 +251,8 @@
                         + "p.s_value, "
                         + "p.s_inherit "
                         + "FROM "
-                        + "s_BranchContents as bc, "
-                        + "s_Properties as p "
+                        + "s_BranchContents bc, "
+                        + "s_Properties p "
                         + "WHERE "
                         + "bc.s_branch = "
                         + branchID
Index: TextArtifactAgent.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/artifact/TextArtifactAgent.java,v
retrieving revision 1.13
diff -u -r1.13 TextArtifactAgent.java
--- TextArtifactAgent.java	1 Sep 2002 18:56:36 -0000	1.13
+++ TextArtifactAgent.java	2 Sep 2002 18:00:15 -0000
@@ -262,10 +262,10 @@
                         + "bc.s_exec,"
                         + "v.s_time "
                         + "FROM "
-                        + "s_BranchContents as bc, "
-                        + "s_Artifacts as ai,"
-                        + "s_Versions as v,"
-                        + "s_Branches as branches "
+                        + "s_BranchContents bc, "
+                        + "s_Artifacts ai,"
+                        + "s_Versions v,"
+                        + "s_Branches branches "
                         + "WHERE "
                         + "branches.s_project = ? "
                         + "AND branches.s_name = ? "
@@ -287,9 +287,9 @@
                         + LINENUM
                         + " FROM "
                         + LINES_TABLE
-                        + " as t_lines, "
+                        + " t_lines, "
                         + VERSIONS_TABLE
-                        + " as t_versions "
+                        + " t_versions "
                         + " WHERE t_lines."
                         + LINEID
                         + " = t_versions."
Index: DataArtifactAgent.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/artifact/DataArtifactAgent.java,v
retrieving revision 1.9
diff -u -r1.9 DataArtifactAgent.java
--- DataArtifactAgent.java	1 Sep 2002 18:56:36 -0000	1.9
+++ DataArtifactAgent.java	2 Sep 2002 18:02:13 -0000
@@ -195,11 +195,11 @@
                                   "v.s_time," +
                                   "bc.s_exec " +
                                   "FROM " +
-                                  "s_BranchContents as bc, " +
-                                  "s_Datas as d," +
-                                  "s_Artifacts as ai," +
-                                  "s_Branches as branches," +
-                                  "s_Versions as v " +
+                                  "s_BranchContents bc, " +
+                                  "s_Datas d," +
+                                  "s_Artifacts ai," +
+                                  "s_Branches branches," +
+                                  "s_Versions v " +
                                   "WHERE " +
                                   "branches.s_project = ? " +
                                   "AND branches.s_name = ? " +
Index: LinkArtifactAgent.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/artifact/LinkArtifactAgent.java,v
retrieving revision 1.7
diff -u -r1.7 LinkArtifactAgent.java
--- LinkArtifactAgent.java	1 Sep 2002 18:56:36 -0000	1.7
+++ LinkArtifactAgent.java	2 Sep 2002 18:02:46 -0000
@@ -179,11 +179,11 @@
                         + "l.s_target,"
                         + "v.s_time "
                         + "FROM "
-                        + "s_BranchContents as bc, "
-                        + "s_Links as l,"
-                        + "s_Artifacts as ai, "
-                        + "s_Branches as branches,"
-                        + "s_Versions as v "
+                        + "s_BranchContents bc, "
+                        + "s_Links l,"
+                        + "s_Artifacts ai, "
+                        + "s_Branches branches,"
+                        + "s_Versions v "
                         + "WHERE "
                         + "branches.s_project = ? "
                         + "AND branches.s_name = ? "
Index: CompoundArtifactAgent.java
===================================================================
RCS file: /home/technology/org.eclipse.stellation/plugins/org.eclipse.stellation.core/src/org/eclipse/stellation/repos/artifact/CompoundArtifactAgent.java,v
retrieving revision 1.7
diff -u -r1.7 CompoundArtifactAgent.java
--- CompoundArtifactAgent.java	1 Sep 2002 18:56:36 -0000	1.7
+++ CompoundArtifactAgent.java	2 Sep 2002 18:03:24 -0000
@@ -322,9 +322,9 @@
                         + "c.s_name, "
                         + "c.s_memberid "
                         + "FROM "
-                        + "s_BranchContents as bc,"
-                        + "s_Compounds as c, "
-                        + "s_Branches as branches "
+                        + "s_BranchContents bc,"
+                        + "s_Compounds c, "
+                        + "s_Branches branches "
                         + "WHERE "
                         + "branches.s_project = ? "
                         + "AND  branches.s_name = ? "
@@ -389,9 +389,9 @@
                 "SELECT bc.s_aid,"
                     + "bc.s_vid "
                     + "FROM "
-                    + "s_BranchContents as bc,"
-                    + "s_Artifacts as ai, "
-                    + "s_Branches as branches "
+                    + "s_BranchContents bc,"
+                    + "s_Artifacts ai, "
+                    + "s_Branches branches "
                     + "WHERE "
                     + "branches.s_project = '"
                     + project

Back to the top