incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1006292 - in /incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database: DBInterfaceHSQLDB.java Database.java
Date Sun, 10 Oct 2010 13:16:11 GMT
Author: kwright
Date: Sun Oct 10 13:16:11 2010
New Revision: 1006292

URL: http://svn.apache.org/viewvc?rev=1006292&view=rev
Log:
Fix what's needed for hsqldb to at least start to run.

Modified:
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java

Modified: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java?rev=1006292&r1=1006291&r2=1006292&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
Sun Oct 10 13:16:11 2010
@@ -1007,6 +1007,10 @@ public class DBInterfaceHSQLDB extends D
     beginTransaction(TRANSACTION_ENCLOSING);
   }
 
+  protected int depthCount = 0;
+  protected boolean inTransaction = false;
+  protected int desiredTransactionType = Connection.TRANSACTION_READ_COMMITTED;
+
   /** Begin a database transaction.  This method call MUST be paired with an endTransaction()
call,
   * or database handles will be lost.  If the transaction should be rolled back, then signalRollback()
should
   * be called before the transaction is ended.
@@ -1033,26 +1037,12 @@ public class DBInterfaceHSQLDB extends D
     switch (transactionType)
     {
     case TRANSACTION_READCOMMITTED:
+      desiredTransactionType = Connection.TRANSACTION_READ_COMMITTED;
       super.beginTransaction(TRANSACTION_READCOMMITTED);
       break;
     case TRANSACTION_SERIALIZED:
+      desiredTransactionType = Connection.TRANSACTION_SERIALIZABLE;
       super.beginTransaction(TRANSACTION_SERIALIZED);
-      try
-      {
-        performModification("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE",null,null);
-      }
-      catch (Error e)
-      {
-        super.signalRollback();
-        super.endTransaction();
-        throw e;
-      }
-      catch (ManifoldCFException e)
-      {
-        super.signalRollback();
-        super.endTransaction();
-        throw e;
-      }
       break;
     default:
       throw new ManifoldCFException("Bad transaction type: "+Integer.toString(transactionType));
@@ -1082,25 +1072,81 @@ public class DBInterfaceHSQLDB extends D
     super.endTransaction();
   }
 
+
   /** Abstract method to start a transaction */
   protected void startATransaction()
     throws ManifoldCFException
   {
-    executeViaThread(connection,"START TRANSACTION",null,false,0,null,null);
+    if (!inTransaction)
+    {
+      try
+      {
+        connection.setAutoCommit(false);
+        connection.setTransactionIsolation(desiredTransactionType);
+      }
+      catch (java.sql.SQLException e)
+      {
+        throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.DATABASE_CONNECTION_ERROR);
+      }
+      inTransaction = true;
+    }
+    depthCount++;
   }
 
   /** Abstract method to commit a transaction */
   protected void commitCurrentTransaction()
     throws ManifoldCFException
   {
-    executeViaThread(connection,"COMMIT",null,false,0,null,null);
+    if (inTransaction)
+    {
+      if (depthCount == 1)
+      {
+        try
+        {
+          if (connection != null)
+          {
+            connection.commit();
+            connection.setAutoCommit(true);
+          }
+        }
+        catch (java.sql.SQLException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.DATABASE_CONNECTION_ERROR);
+        }
+        inTransaction = false;
+      }
+      depthCount--;
+    }
+    else
+      throw new ManifoldCFException("Transaction nesting error!");
   }
   
   /** Abstract method to roll back a transaction */
   protected void rollbackCurrentTransaction()
     throws ManifoldCFException
   {
-    executeViaThread(connection,"ROLLBACK",null,false,0,null,null);
+    if (inTransaction)
+    {
+      if (depthCount == 1)
+      {
+        try
+        {
+          if (connection != null)
+          {
+            connection.rollback();
+            connection.setAutoCommit(true);
+          }
+        }
+        catch (java.sql.SQLException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.DATABASE_CONNECTION_ERROR);
+        }
+        inTransaction = false;
+      }
+      depthCount--;
+    }
+    else
+      throw new ManifoldCFException("Transaction nesting error!");
   }
   
   /** Abstract method for mapping a column name from resultset */

Modified: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1006292&r1=1006291&r2=1006292&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
Sun Oct 10 13:16:11 2010
@@ -604,6 +604,7 @@ public class Database
         {
           int colcount = 0;
           String[] resultCols = null;
+          String[] resultLabels = null;
 
           // Optionally we're going to suck the data
           // out of the db and return it in a
@@ -616,9 +617,11 @@ public class Database
             //LogBean.db.debug(colcount + " columns returned.");
 
             resultCols = new String[colcount];
+            resultLabels = new String[colcount];
             for (int i = 0; i < colcount; i++)
             {
-              resultCols[i] = mapColumnName(rsmd.getColumnName(i+1));
+              resultCols[i] = rsmd.getColumnName(i+1);
+              resultLabels[i] = mapColumnName(rsmd.getColumnLabel(i+1));
             }
           }
 
@@ -633,7 +636,7 @@ public class Database
 
             while (rs.next() && (maxResults == -1 || maxResults > 0) &&
(returnLimit == null || returnLimit.checkContinue()))
             {
-              Object value = null;
+              Object value;
               RRow m = new RRow();
 
               // We have 'colcount' cols to look thru
@@ -642,11 +645,13 @@ public class Database
                 String key = resultCols[i];
                 // System.out.println("Key = "+key);
                 int colnum = findColumn(rs,key);
+                value = null;
                 if (colnum > -1)
                 {
                   value = getObject(rs,rsmd,colnum,(spec == null)?ResultSpecification.FORM_DEFAULT:spec.getForm(key));
                 }
-                m.put(key, value);
+                //System.out.println(" Key = '"+resultLabels[i]+"', value = "+((value==null)?"NULL":value.toString()));
+                m.put(resultLabels[i], value);
               }
 
               // See if we should include this row
@@ -909,6 +914,7 @@ public class Database
           switch (rsmd.getColumnType(col))
           {
           case java.sql.Types.CHAR :
+          case java.sql.Types.VARCHAR :
             if ((resultString = rs.getString(col)) != null)
             {
               if (rsmd.getColumnDisplaySize(col) < resultString.length())
@@ -925,6 +931,7 @@ public class Database
               result = clob.getSubString(1, (int) clob.length());
             }
             break;
+            
           case java.sql.Types.BIGINT :
             long l = rs.getLong(col);
             if (!rs.wasNull())
@@ -937,6 +944,12 @@ public class Database
               result = new Integer(i);
             break;
 
+          case java.sql.Types.SMALLINT:
+            short s = rs.getShort(col);
+            if (!rs.wasNull())
+              result = new Short(s);
+            break;
+
           case java.sql.Types.REAL :
           case java.sql.Types.FLOAT :
             float f = rs.getFloat(col);
@@ -964,6 +977,12 @@ public class Database
             }
             break;
 
+          case java.sql.Types.BOOLEAN :
+            boolean b = rs.getBoolean(col);
+            if (!rs.wasNull())
+              result = new Boolean(b);
+            break;
+
           case java.sql.Types.BLOB:
             throw new ManifoldCFException("BLOB is not a string, column = " + col,ManifoldCFException.GENERAL_ERROR);
 



Mime
View raw message