You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2010/06/02 04:40:42 UTC
svn commit: r950342 - in /incubator/lcf/trunk/modules/framework:
core/org/apache/lcf/core/database/ core/org/apache/lcf/core/interfaces/
pull-agent/org/apache/lcf/crawler/jobs/
pull-agent/org/apache/lcf/crawler/repository/
Author: kwright
Date: Wed Jun 2 02:40:42 2010
New Revision: 950342
URL: http://svn.apache.org/viewvc?rev=950342&view=rev
Log:
Revamp database layer to allow abstraction of transactions, and change the schema so that Derby's keywords don't blow up install.
Removed:
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DatabaseFactory.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDatabase.java
Modified:
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/Database.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java Wed Jun 2 02:40:42 2010
@@ -23,15 +23,13 @@ import org.apache.lcf.core.system.Loggin
import java.util.*;
import java.io.*;
-public class DBInterfaceDerby implements IDBInterface
+public class DBInterfaceDerby extends Database implements IDBInterface
{
public static final String _rcsid = "@(#)$Id$";
protected final static String _url = "jdbc:derby:";
protected final static String _driver = "org.apache.derby.jdbc.EmbeddedDriver";
- protected IThreadContext context;
- protected IDatabase database;
protected String userName;
protected String password;
@@ -43,31 +41,12 @@ public class DBInterfaceDerby implements
public DBInterfaceDerby(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- this.context = tc;
- if (databaseName == null)
- databaseName = "default";
- database = DatabaseFactory.make(tc,_url+databaseName+";create=true;user="+userName+";password="+password,_driver,databaseName,userName,password);
- cacheKey = CacheKeyFactory.makeDatabaseKey(databaseName);
+ super(tc,_url+((databaseName==null)?"default":databaseName)+";create=true;user="+userName+";password="+password,_driver,((databaseName==null)?"default":databaseName),userName,password);
+ cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
this.userName = userName;
this.password = password;
}
- /** Get the database name.
- *@return the database name.
- */
- public String getDatabaseName()
- {
- return database.getDatabaseName();
- }
-
- /** Get the current transaction id.
- *@return the current transaction identifier, or null if no transaction.
- */
- public String getTransactionID()
- {
- return database.getTransactionID();
- }
-
/** Get the database general cache key.
*@return the general cache key for the database.
*/
@@ -483,7 +462,7 @@ public class DBInterfaceDerby implements
public boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
throws LCFException
{
- IDatabase rootDatabase = DatabaseFactory.make(context,_url+database.getDatabaseName()+";create=true",_driver,database.getDatabaseName(),"","");
+ Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
IResultSet set = rootDatabase.executeQuery("VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('derby.user."+userName+"')",null,cacheKeys,null,queryClass,true,-1,null,null);
if (set.getRowCount() == 0)
return false;
@@ -497,7 +476,7 @@ public class DBInterfaceDerby implements
public void performCreateUser(String userName, String password)
throws LCFException
{
- IDatabase rootDatabase = DatabaseFactory.make(context,_url+database.getDatabaseName()+";create=true",_driver,database.getDatabaseName(),"","");
+ Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"', '"+password+"')",null,null,null,null,false,0,null,null);
rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,null,null,null,false,0,null,null);
}
@@ -508,7 +487,7 @@ public class DBInterfaceDerby implements
public void performDropUser(String userName)
throws LCFException
{
- IDatabase rootDatabase = DatabaseFactory.make(context,_url+database.getDatabaseName()+";create=true",_driver,database.getDatabaseName(),"","");
+ Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
rootDatabase.executeQuery("DROP SCHEMA "+userName+" RESTRICT",null,null,null,null,false,0,null,null);
rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"', null)",null,null,null,null,false,0,null,null);
}
@@ -611,7 +590,7 @@ public class DBInterfaceDerby implements
{
try
{
- database.executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
+ executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
}
catch (LCFException e)
{
@@ -629,9 +608,9 @@ public class DBInterfaceDerby implements
public Map getTableSchema(String tableName, StringSet cacheKeys, String queryClass)
throws LCFException
{
- String query = "SELECT t0.columnname,t0.columndatatype FROM sys.syscolumns t0, sys.systables t1 WHERE t0.referenceid=t1.tableid AND CAST(t1.tablename AS VARCHAR(128))=? ORDER BY t0.columnnumber ASC";
+ String query = "SELECT CAST(t0.columnname AS VARCHAR(128)) AS columnname,CAST(t0.columndatatype AS VARCHAR(128)) AS columndatatype FROM sys.syscolumns t0, sys.systables t1 WHERE t0.referenceid=t1.tableid AND CAST(t1.tablename AS VARCHAR(128))=? ORDER BY t0.columnnumber ASC";
ArrayList list = new ArrayList();
- list.add(tableName);
+ list.add(tableName.toUpperCase());
IResultSet set = performQuery(query,list,cacheKeys,queryClass);
if (set.getRowCount() == 0)
@@ -642,8 +621,8 @@ public class DBInterfaceDerby implements
while (i < set.getRowCount())
{
IResultRow row = set.getRow(i++);
- String fieldName = row.getValue("columnname").toString();
- String type = row.getValue("columndatatype").toString();
+ String fieldName = (String)row.getValue("columnname");
+ String type = (String)row.getValue("columndatatype");
boolean isNull = false;
boolean isPrimaryKey = false;
rval.put(fieldName,new ColumnDescription(type,isPrimaryKey,isNull,null,null,false));
@@ -720,7 +699,7 @@ public class DBInterfaceDerby implements
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
}
catch (LCFException e)
{
@@ -744,7 +723,7 @@ public class DBInterfaceDerby implements
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
}
catch (LCFException e)
{
@@ -769,7 +748,7 @@ public class DBInterfaceDerby implements
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
}
catch (LCFException e)
{
@@ -848,7 +827,7 @@ public class DBInterfaceDerby implements
public void beginTransaction(int transactionType)
throws LCFException
{
- if (database.getCurrentTransactionType() == database.TRANSACTION_SERIALIZED)
+ if (getCurrentTransactionType() == TRANSACTION_SERIALIZED)
{
serializableDepth++;
return;
@@ -856,18 +835,7 @@ public class DBInterfaceDerby implements
if (transactionType == TRANSACTION_ENCLOSING)
{
- int enclosingTransactionType = database.getCurrentTransactionType();
- switch (enclosingTransactionType)
- {
- case IDatabase.TRANSACTION_READCOMMITTED:
- transactionType = TRANSACTION_READCOMMITTED;
- break;
- case IDatabase.TRANSACTION_SERIALIZED:
- transactionType = TRANSACTION_SERIALIZED;
- break;
- default:
- throw new LCFException("Unknown transaction type");
- }
+ transactionType = super.getCurrentTransactionType();
}
switch (transactionType)
@@ -875,40 +843,40 @@ public class DBInterfaceDerby implements
case TRANSACTION_READCOMMITTED:
try
{
- performModification("SET ISOLATION READ COMMITTED",null,null);
+ executeViaThread(connection,"SET ISOLATION READ COMMITTED",null,false,0,null,null);
}
catch (Error e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
catch (LCFException e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
- database.beginTransaction(database.TRANSACTION_READCOMMITTED);
+ super.beginTransaction(TRANSACTION_READCOMMITTED);
break;
case TRANSACTION_SERIALIZED:
try
{
- performModification("SET ISOLATION SERIALIZABLE",null,null);
+ executeViaThread(connection,"SET ISOLATION SERIALIZABLE",null,false,0,null,null);
}
catch (Error e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
catch (LCFException e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
- database.beginTransaction(database.TRANSACTION_SERIALIZED);
+ super.beginTransaction(TRANSACTION_SERIALIZED);
break;
default:
throw new LCFException("Bad transaction type");
@@ -920,7 +888,7 @@ public class DBInterfaceDerby implements
public void signalRollback()
{
if (serializableDepth == 0)
- database.signalRollback();
+ super.signalRollback();
}
/** End a database transaction, either performing a commit or a rollback (depending on whether
@@ -935,7 +903,77 @@ public class DBInterfaceDerby implements
return;
}
- database.endTransaction();
+ super.endTransaction();
+ }
+
+ int depthCount = 0;
+ boolean inTransaction = false;
+
+ /** Abstract method to start a transaction */
+ protected void startATransaction()
+ throws LCFException
+ {
+ if (!inTransaction)
+ {
+ try
+ {
+ connection.setAutoCommit(false);
+ }
+ catch (java.sql.SQLException e)
+ {
+ throw new LCFException(e.getMessage(),e);
+ }
+ inTransaction = true;
+ }
+ depthCount++;
+ }
+
+ /** Abstract method to commit a transaction */
+ protected void commitCurrentTransaction()
+ throws LCFException
+ {
+ if (inTransaction)
+ {
+ depthCount--;
+ if (depthCount == 0)
+ {
+ try
+ {
+ connection.commit();
+ }
+ catch (java.sql.SQLException e)
+ {
+ throw new LCFException(e.getMessage(),e);
+ }
+ inTransaction = false;
+ }
+ }
+ else
+ throw new LCFException("Transaction nesting error!");
+ }
+
+ /** Abstract method to roll back a transaction */
+ protected void rollbackCurrentTransaction()
+ throws LCFException
+ {
+ if (inTransaction)
+ {
+ depthCount--;
+ if (depthCount == 0)
+ {
+ try
+ {
+ connection.rollback();
+ }
+ catch (java.sql.SQLException e)
+ {
+ throw new LCFException(e.getMessage(),e);
+ }
+ inTransaction = false;
+ }
+ }
+ else
+ throw new LCFException("Transaction nesting error!");
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java Wed Jun 2 02:40:42 2010
@@ -21,7 +21,7 @@ package org.apache.lcf.core.database;
import org.apache.lcf.core.interfaces.*;
import java.util.*;
-public class DBInterfaceMySQL implements IDBInterface
+public class DBInterfaceMySQL extends Database implements IDBInterface
{
public static final String _rcsid = "@(#)$Id$";
@@ -29,33 +29,13 @@ public class DBInterfaceMySQL implements
private static final String _driver = "org.gjt.mm.mysql.Driver";
protected IThreadContext context;
- protected IDatabase database;
protected String cacheKey;
public DBInterfaceMySQL(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- this.context = tc;
- if (databaseName == null)
- databaseName = "mysql";
- database = DatabaseFactory.make(tc,_url+databaseName,_driver,databaseName,userName,password);
- cacheKey = CacheKeyFactory.makeDatabaseKey(databaseName);
- }
-
- /** Get the database name.
- *@return the database name.
- */
- public String getDatabaseName()
- {
- return database.getDatabaseName();
- }
-
- /** Get the current transaction id.
- *@return the current transaction identifier, or null if no transaction.
- */
- public String getTransactionID()
- {
- return database.getTransactionID();
+ super(tc,_url+databaseName,_driver,(databaseName==null)?"mysql":databaseName,userName,password);
+ cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
}
/** Get the database general cache key.
@@ -477,7 +457,7 @@ public class DBInterfaceMySQL implements
public void performModification(String query, ArrayList params, StringSet invalidateKeys)
throws LCFException
{
- database.executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
+ executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
}
/** Get a table's schema.
@@ -529,7 +509,7 @@ public class DBInterfaceMySQL implements
{
IResultSet set = performQuery("SHOW TABLES",null,cacheKeys,queryClass);
StringSetBuffer ssb = new StringSetBuffer();
- String columnName = "Tables_in_"+database.getDatabaseName().toLowerCase();
+ String columnName = "Tables_in_"+databaseName.toLowerCase();
// System.out.println(columnName);
int i = 0;
@@ -556,7 +536,7 @@ public class DBInterfaceMySQL implements
public IResultSet performQuery(String query, ArrayList params, StringSet cacheKeys, String queryClass)
throws LCFException
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
}
/** Perform a general "data fetch" query.
@@ -573,7 +553,7 @@ public class DBInterfaceMySQL implements
int maxResults, ILimitChecker returnLimit)
throws LCFException
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
}
/** Perform a general "data fetch" query.
@@ -591,7 +571,7 @@ public class DBInterfaceMySQL implements
int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
throws LCFException
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
}
/** Quote a sql string.
@@ -650,7 +630,7 @@ public class DBInterfaceMySQL implements
public void beginTransaction()
throws LCFException
{
- database.beginTransaction(database.TRANSACTION_READCOMMITTED);
+ super.beginTransaction(TRANSACTION_READCOMMITTED);
}
/** Begin a database transaction. This method call MUST be paired with an endTransaction() call,
@@ -665,25 +645,29 @@ public class DBInterfaceMySQL implements
public void beginTransaction(int transactionType)
throws LCFException
{
- database.beginTransaction(database.TRANSACTION_READCOMMITTED);
+ super.beginTransaction(TRANSACTION_READCOMMITTED);
}
- /** Signal that a rollback should occur on the next endTransaction().
- */
- public void signalRollback()
+ /** Abstract method to start a transaction */
+ protected void startATransaction()
+ throws LCFException
{
- database.signalRollback();
+ executeViaThread(connection,"START TRANSACTION",null,false,0,null,null);
}
- /** End a database transaction, either performing a commit or a rollback (depending on whether
- * signalRollback() was called within the transaction).
- */
- public void endTransaction()
+ /** Abstract method to commit a transaction */
+ protected void commitCurrentTransaction()
throws LCFException
{
- database.endTransaction();
+ executeViaThread(connection,"COMMIT",null,false,0,null,null);
+ }
+
+ /** Abstract method to roll back a transaction */
+ protected void rollbackCurrentTransaction()
+ throws LCFException
+ {
+ executeViaThread(connection,"ROLLBACK",null,false,0,null,null);
}
-
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java Wed Jun 2 02:40:42 2010
@@ -22,17 +22,13 @@ import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.core.system.Logging;
import java.util.*;
-public class DBInterfacePostgreSQL implements IDBInterface
+public class DBInterfacePostgreSQL extends Database implements IDBInterface
{
public static final String _rcsid = "@(#)$Id$";
private static final String _url = "jdbc:postgresql://localhost/";
- // private static final String _url = "jdbc:mysql://localhost/";
private static final String _driver = "org.postgresql.Driver";
- // private static final String _driver = "org.gjt.mm.mysql.Driver";
- protected IThreadContext context;
- protected IDatabase database;
protected String cacheKey;
// Postgresql serializable transactions are broken in that transactions that occur within them do not in fact work properly.
// So, once we enter the serializable realm, STOP any additional transactions from doing anything at all.
@@ -47,27 +43,8 @@ public class DBInterfacePostgreSQL imple
public DBInterfacePostgreSQL(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- this.context = tc;
- if (databaseName == null)
- databaseName = "template1";
- database = DatabaseFactory.make(tc,_url+databaseName,_driver,databaseName,userName,password);
- cacheKey = CacheKeyFactory.makeDatabaseKey(databaseName);
- }
-
- /** Get the database name.
- *@return the database name.
- */
- public String getDatabaseName()
- {
- return database.getDatabaseName();
- }
-
- /** Get the current transaction id.
- *@return the current transaction identifier, or null if no transaction.
- */
- public String getTransactionID()
- {
- return database.getTransactionID();
+ super(tc,_url+((databaseName==null)?"template1":databaseName),_driver,((databaseName==null)?"template1":databaseName),userName,password);
+ cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
}
/** Get the database general cache key.
@@ -599,7 +576,7 @@ public class DBInterfacePostgreSQL imple
{
try
{
- database.executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
+ executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
}
catch (LCFException e)
{
@@ -767,7 +744,7 @@ public class DBInterfacePostgreSQL imple
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
}
catch (LCFException e)
{
@@ -791,7 +768,7 @@ public class DBInterfacePostgreSQL imple
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
}
catch (LCFException e)
{
@@ -816,7 +793,7 @@ public class DBInterfacePostgreSQL imple
{
try
{
- return database.executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
+ return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
}
catch (LCFException e)
{
@@ -880,7 +857,7 @@ public class DBInterfacePostgreSQL imple
public void beginTransaction()
throws LCFException
{
- beginTransaction(TRANSACTION_ENCLOSING);
+ super.beginTransaction(TRANSACTION_ENCLOSING);
}
/** Begin a database transaction. This method call MUST be paired with an endTransaction() call,
@@ -895,7 +872,7 @@ public class DBInterfacePostgreSQL imple
public void beginTransaction(int transactionType)
throws LCFException
{
- if (database.getCurrentTransactionType() == database.TRANSACTION_SERIALIZED)
+ if (getCurrentTransactionType() == TRANSACTION_SERIALIZED)
{
serializableDepth++;
return;
@@ -903,41 +880,30 @@ public class DBInterfacePostgreSQL imple
if (transactionType == TRANSACTION_ENCLOSING)
{
- int enclosingTransactionType = database.getCurrentTransactionType();
- switch (enclosingTransactionType)
- {
- case IDatabase.TRANSACTION_READCOMMITTED:
- transactionType = TRANSACTION_READCOMMITTED;
- break;
- case IDatabase.TRANSACTION_SERIALIZED:
- transactionType = TRANSACTION_SERIALIZED;
- break;
- default:
- throw new LCFException("Unknown transaction type");
- }
+ transactionType = getCurrentTransactionType();
}
switch (transactionType)
{
case TRANSACTION_READCOMMITTED:
- database.beginTransaction(database.TRANSACTION_READCOMMITTED);
+ super.beginTransaction(TRANSACTION_READCOMMITTED);
break;
case TRANSACTION_SERIALIZED:
- database.beginTransaction(database.TRANSACTION_SERIALIZED);
+ super.beginTransaction(TRANSACTION_SERIALIZED);
try
{
performModification("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE",null,null);
}
catch (Error e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
catch (LCFException e)
{
- database.signalRollback();
- database.endTransaction();
+ super.signalRollback();
+ super.endTransaction();
throw e;
}
break;
@@ -951,7 +917,7 @@ public class DBInterfacePostgreSQL imple
public void signalRollback()
{
if (serializableDepth == 0)
- database.signalRollback();
+ super.signalRollback();
}
/** End a database transaction, either performing a commit or a rollback (depending on whether
@@ -966,7 +932,7 @@ public class DBInterfacePostgreSQL imple
return;
}
- database.endTransaction();
+ super.endTransaction();
if (getTransactionID() == null)
{
int i = 0;
@@ -984,6 +950,43 @@ public class DBInterfacePostgreSQL imple
}
}
+ /** Abstract method to start a transaction */
+ protected void startATransaction()
+ throws LCFException
+ {
+ executeViaThread(connection,"START TRANSACTION",null,false,0,null,null);
+ }
+
+ /** Abstract method to commit a transaction */
+ protected void commitCurrentTransaction()
+ throws LCFException
+ {
+ executeViaThread(connection,"COMMIT",null,false,0,null,null);
+ }
+
+ /** Abstract method to roll back a transaction */
+ protected void rollbackCurrentTransaction()
+ throws LCFException
+ {
+ executeViaThread(connection,"ROLLBACK",null,false,0,null,null);
+ }
+
+ /** Abstract method for explaining a query */
+ protected void explainQuery(String query, ArrayList params)
+ throws LCFException
+ {
+ IResultSet x = executeUncachedQuery("EXPLAIN "+query,params,true,
+ -1,null,null);
+ int k = 0;
+ while (k < x.getRowCount())
+ {
+ IResultRow row = x.getRow(k++);
+ Iterator iter = row.getColumns();
+ String colName = (String)iter.next();
+ Logging.db.warn(" Plan: "+row.getValue(colName).toString());
+ }
+ Logging.db.warn("");
+ }
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/Database.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/Database.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/Database.java Wed Jun 2 02:40:42 2010
@@ -32,7 +32,7 @@ import javax.sql.*;
* the transaction management will get screwed up (i.e. nobody will know what happened to the connection
* handles...)
*/
-public class Database implements IDatabase
+public class Database
{
public static final String _rcsid = "@(#)$Id$";
@@ -49,9 +49,6 @@ public class Database implements IDataba
protected int delayedTransactionDepth = 0;
protected final static String _TRANSACTION_ = "_TRANSACTION_";
- protected final static String BEGIN_TRANSACTION = "START TRANSACTION";
- protected final static String END_TRANSACTION = "COMMIT";
- protected final static String ROLLBACK_TRANSACTION = "ROLLBACK";
public Database(IThreadContext context, String jdbcUrl, String jdbcDriverClass, String databaseName, String userName, String password)
throws LCFException
@@ -83,6 +80,30 @@ public class Database implements IDataba
return th.getTransactionID();
}
+ /** Abstract method to start a transaction */
+ protected void startATransaction()
+ throws LCFException
+ {
+ }
+
+ /** Abstract method to commit a transaction */
+ protected void commitCurrentTransaction()
+ throws LCFException
+ {
+ }
+
+ /** Abstract method to roll back a transaction */
+ protected void rollbackCurrentTransaction()
+ throws LCFException
+ {
+ }
+
+ /** Abstract method for explaining a query */
+ protected void explainQuery(String query, ArrayList params)
+ throws LCFException
+ {
+ }
+
/** Execute arbitrary database query, and optionally cache the result. Cached results are
* returned for this operation if they are valid and appropriate. Note that any cached results
* returned were only guaranteed to be pertinent at the time the cached result was obtained; the
@@ -148,7 +169,7 @@ public class Database implements IDataba
public int getCurrentTransactionType()
{
if (th == null)
- return TRANSACTION_READCOMMITTED;
+ return IDBInterface.TRANSACTION_READCOMMITTED;
return th.getTransactionType();
}
@@ -204,16 +225,15 @@ public class Database implements IDataba
try
{
// Start a transaction
- executeViaThread(connection,BEGIN_TRANSACTION,null,false,0,null,null);
- }
- catch (InterruptedException e)
- {
- // Don't do anything else other than drop the connection on the floor
- connection = null;
- throw new LCFException("Interrupted: "+e.getMessage(),e,LCFException.INTERRUPTED);
+ startATransaction();
}
catch (LCFException e)
{
+ if (e.getErrorCode() == LCFException.INTERRUPTED)
+ {
+ connection = null;
+ throw e;
+ }
ConnectionFactory.releaseConnection(connection);
connection = null;
throw e;
@@ -229,13 +249,16 @@ public class Database implements IDataba
{
try
{
- executeViaThread(connection,BEGIN_TRANSACTION,null,false,0,null,null);
+ startATransaction();
}
- catch (InterruptedException e)
+ catch (LCFException e)
{
- // Don't do anything else other than drop the connection on the floor
- connection = null;
- throw new LCFException("Interrupted: "+e.getMessage(),e,LCFException.INTERRUPTED);
+ if (e.getErrorCode() == LCFException.INTERRUPTED)
+ {
+ // Don't do anything else other than drop the connection on the floor
+ connection = null;
+ }
+ throw e;
}
}
}
@@ -275,20 +298,23 @@ public class Database implements IDataba
{
// Do a rollback in the database, and blow away cached queries (cached against the
// database transaction key).
- executeViaThread(connection,ROLLBACK_TRANSACTION,null,false,0,null,null);
+ rollbackCurrentTransaction();
}
else
{
// Do a commit into the database, and blow away cached queries (cached against the
// database transaction key).
- executeViaThread(connection,END_TRANSACTION,null,false,0,null,null);
+ commitCurrentTransaction();
}
}
- catch (InterruptedException e)
+ catch (LCFException e)
{
- // Drop the connection on the floor, so it cannot be reused.
- connection = null;
- throw new LCFException("Interrupted: "+e.getMessage(),e,LCFException.INTERRUPTED);
+ if (e.getErrorCode() == LCFException.INTERRUPTED)
+ {
+ // Drop the connection on the floor, so it cannot be reused.
+ connection = null;
+ }
+ throw e;
}
finally
{
@@ -368,7 +394,7 @@ public class Database implements IDataba
/** Do query execution via a subthread, so the primary thread can be interrupted */
protected IResultSet executeViaThread(Connection connection, String query, ArrayList params, boolean bResults, int maxResults,
ResultSpecification spec, ILimitChecker returnLimit)
- throws LCFException, InterruptedException
+ throws LCFException
{
if (connection == null)
// This probably means that the thread was interrupted and the connection was abandoned. Just return null.
@@ -397,7 +423,7 @@ public class Database implements IDataba
{
t.interrupt();
// We need the caller to abandon any connections left around, so rethrow in a way that forces them to process the event properly.
- throw e;
+ throw new LCFException(e.getMessage(),e,LCFException.INTERRUPTED);
}
}
@@ -416,11 +442,12 @@ public class Database implements IDataba
{
return executeViaThread(connection,query,params,bResults,maxResults,spec,returnLimit);
}
- catch (InterruptedException e)
+ catch (LCFException e)
{
- // drop the connection object on the floor, so it cannot possibly be reused
- connection = null;
- throw new LCFException("Interrupted: "+e.getMessage(),e,LCFException.INTERRUPTED);
+ if (e.getErrorCode() == LCFException.INTERRUPTED)
+ // drop the connection object on the floor, so it cannot possibly be reused
+ connection = null;
+ throw e;
}
}
else
@@ -431,11 +458,12 @@ public class Database implements IDataba
{
return executeViaThread(tempConnection,query,params,bResults,maxResults,spec,returnLimit);
}
- catch (InterruptedException e)
+ catch (LCFException e)
{
- // drop the connection object on the floor, so it cannot possibly be reused
- tempConnection = null;
- throw new LCFException("Interrupted: "+e.getMessage(),e,LCFException.INTERRUPTED);
+ if (e.getErrorCode() == LCFException.INTERRUPTED)
+ // drop the connection object on the floor, so it cannot possibly be reused
+ tempConnection = null;
+ throw e;
}
finally
{
@@ -1054,17 +1082,7 @@ public class Database implements IDataba
}
try
{
- IResultSet x = database.executeUncachedQuery("EXPLAIN "+description.getQuery(),description.getParameters(),true,
- -1,null,null);
- int k = 0;
- while (k < x.getRowCount())
- {
- IResultRow row = x.getRow(k++);
- Iterator iter = row.getColumns();
- String colName = (String)iter.next();
- Logging.db.warn(" Plan: "+row.getValue(colName).toString());
- }
- Logging.db.warn("");
+ database.explainQuery(description.getQuery(),description.getParameters());
}
catch (LCFException e)
{
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java Wed Jun 2 02:40:42 2010
@@ -36,7 +36,7 @@ public class ScheduleManager extends org
public final static String dayOfWeekField = "dayofweek";
public final static String dayOfMonthField = "dayofmonth";
public final static String monthOfYearField = "monthofyear";
- public final static String yearField = "year";
+ public final static String yearField = "yearlist";
public final static String hourOfDayField = "hourofday";
public final static String minutesOfHourField = "minutesofhour";
public final static String timezoneField = "timezone";
@@ -82,6 +82,18 @@ public class ScheduleManager extends org
else
{
// Upgrade code goes here, if needed.
+ if (existing.get(yearField) == null)
+ {
+ // Need to rename the "year" column as the "yearlist" column.
+ HashMap map = new HashMap();
+ map.put(yearField,new ColumnDescription("VARCHAR(255)",false,true,null,null,false));
+ performAlter(map,null,null,null);
+ performModification("UPDATE "+getTableName()+" SET ("+yearField+"=year)",null,null);
+ ArrayList list = new ArrayList();
+ list.add("year");
+ performAlter(null,null,list,null);
+
+ }
}
// Index management
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java?rev=950342&r1=950341&r2=950342&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java Wed Jun 2 02:40:42 2010
@@ -34,7 +34,7 @@ public class ThrottleSpecManager extends
// Schema
public final static String ownerNameField = "ownername";
public final static String descriptionField = "description";
- public final static String matchField = "match";
+ public final static String matchField = "matchstring";
public final static String throttleField = "throttle";
/** Constructor.
@@ -69,6 +69,17 @@ public class ThrottleSpecManager extends
else
{
// Upgrade code goes here, if needed.
+ if (existing.get(matchField) == null)
+ {
+ // Need to rename the "match" column as the "matchstring" column.
+ HashMap map = new HashMap();
+ map.put(matchField,new ColumnDescription("VARCHAR(255)",false,true,null,null,false));
+ performAlter(map,null,null,null);
+ performModification("UPDATE "+getTableName()+" SET ("+matchField+"=match)",null,null);
+ ArrayList list = new ArrayList();
+ list.add("match");
+ performAlter(null,null,list,null);
+ }
}
// Index management