org.objectweb.cjdbc.controller.virtualdatabase
Class VirtualDatabaseWorkerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabaseWorkerThread
All Implemented Interfaces:
java.lang.Runnable

public class VirtualDatabaseWorkerThread
extends java.lang.Thread

This class handles a connection with a C-JDBC driver.

Version:
2.0
Author:
Emmanuel Cecchet , Nicolas Modrzyk , Marc Herbert , Jean-Bernard van Zuylen

Field Summary
private  boolean closed
           
private  Controller controller
           
private  long currentTid
          The following variables represent the state of the connection with the client
private  CJDBCInputStream in
           
private  boolean isKilled
          true ifthis has been killed.
private  Trace logger
          Logger instance.
private  java.lang.String login
           
(package private)  boolean needSkeleton
          Do we require the templates of PreparedStatements?
private  CJDBCOutputStream out
           
private  boolean queryExecutedInThisTransaction
           
private  java.util.HashMap streamedResultSet
           
private  int transactionIsolation
           
private  boolean transactionStarted
           
private  VirtualDatabaseUser user
           
private  VirtualDatabase vdb
          Virtual database instantiating this thread.
private  boolean waitForCommand
           
private  boolean writeQueryExecutedInThisTransaction
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
VirtualDatabaseWorkerThread(Controller controller, VirtualDatabase vdb)
          Creates a new VirtualDatabaseWorkerThread instance.
 
Method Summary
private  void begin()
           
private  void close()
           
private  void closeRemoteResultSet()
           
private  void commit()
           
private  void connectionGetCatalog()
           
private  void connectionGetCatalogs()
           
private  void connectionSetCatalog()
           
private  void connectionSetTransactionIsolation()
           
private  void databaseMetaDataGetAttributes()
           
private  void databaseMetaDataGetBestRowIdentifier()
           
private  void databaseMetaDataGetColumnPrivileges()
           
private  void databaseMetaDataGetColumns()
           
private  void databaseMetaDataGetCrossReference()
           
private  void databaseMetaDataGetDatabaseProductName()
           
private  void databaseMetaDataGetExportedKeys()
           
private  void databaseMetaDataGetImportedKeys()
           
private  void databaseMetaDataGetIndexInfo()
           
private  void databaseMetaDataGetPrimaryKeys()
           
private  void databaseMetaDataGetProcedureColumns()
           
private  void databaseMetaDataGetProcedures()
           
private  void databaseMetaDataGetSchemas()
           
private  void databaseMetaDataGetSuperTables()
           
private  void databaseMetaDataGetSuperTypes()
           
private  void databaseMetaDataGetTablePrivileges()
           
private  void databaseMetaDataGetTables()
           
private  void databaseMetaDataGetTableTypes()
           
private  void databaseMetaDataGetTypeInfo()
           
private  void databaseMetaDataGetUDTs()
           
private  void databaseMetaDataGetVersionColumns()
           
private  void databaseStaticMetadata()
          Get the static metadata key from the socket and return the corresponding metadata.
private  AbstractWriteRequest decodeWriteRequestFromStream()
          Read a write request send by the Connection object.
private  void execReadRequest()
           
private  void execReadStoredProcedure()
           
private  void execWriteRequest()
           
private  void execWriteRequestWithKeys()
          execWriteRequestWithKeys() will probably have soon no difference with execWriteRequest() anymore; then we can get rid of it.
private  void execWriteStoredProcedure()
           
private  void fetchNextResultSetRows()
          Implements streaming: send the next ResultSet chunk to driver, pulling it from ControllerResultSet.
private  void getControllerVersionNumber()
           
 long getTimeActive()
          Get time active
 java.lang.String getUser()
           
private  void getVirtualDatabaseName()
           
private  void putStreamingReferences(ControllerResultSet crs, DriverResultSet drs)
          Keep a reference to both ResultSets, but garbage collect data already sent.
private  void releaseSavepoint()
           
private  void reset()
           
private  void restoreConnectionState()
           
 java.lang.String[] retrieveClientData()
          Retrieve general information on this client
private  void rollback()
           
private  void rollbackToSavepoint()
           
 void run()
          Gets a connection from the connection queue and process it.
private  void sendToDriver(boolean b)
          Send a protocol boolean, prefixed with the appropriate TypeTag
private  void sendToDriver(DriverResultSet drs)
          Serialize a DriverResultSet answer, prefixed with the appropriate TypeTag
private  void sendToDriver(java.lang.Exception e)
           
private  void sendToDriver(int i)
          Send a protocol int, prefixed with the appropriate TypeTag
private  void sendToDriver(long l)
          Send a protocol long, prefixed with the appropriate TypeTag
private  void sendToDriver(java.lang.String str)
          Send a protocol String, prefixed with the appropriate TypeTag
private  void setAutoCommit()
           
private  void setNamedSavepoint()
           
private  boolean setRequestParameters(AbstractRequest request, java.lang.String login, long tid, boolean transactionStarted)
          Set the login and transaction id on the given request.
private  void setUnnamedSavepoint()
           
 void shutdown()
          Shutdown this thread by setting isKilled value to true.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isKilled

private boolean isKilled
true ifthis has been killed.


needSkeleton

boolean needSkeleton
Do we require the templates of PreparedStatements? Needed for parsing


vdb

private VirtualDatabase vdb
Virtual database instantiating this thread.


logger

private Trace logger
Logger instance.


in

private CJDBCInputStream in

out

private CJDBCOutputStream out

user

private VirtualDatabaseUser user

controller

private Controller controller

waitForCommand

private boolean waitForCommand

streamedResultSet

private java.util.HashMap streamedResultSet

currentTid

private long currentTid
The following variables represent the state of the connection with the client


transactionStarted

private boolean transactionStarted

queryExecutedInThisTransaction

private boolean queryExecutedInThisTransaction

writeQueryExecutedInThisTransaction

private boolean writeQueryExecutedInThisTransaction

login

private java.lang.String login

closed

private boolean closed

transactionIsolation

private int transactionIsolation
Constructor Detail

VirtualDatabaseWorkerThread

public VirtualDatabaseWorkerThread(Controller controller,
                                   VirtualDatabase vdb)
Creates a new VirtualDatabaseWorkerThread instance.

Parameters:
controller - the thread was originated from
vdb - the virtual database instantiating this thread.
Method Detail

decodeWriteRequestFromStream

private AbstractWriteRequest decodeWriteRequestFromStream()
                                                   throws java.io.IOException
Read a write request send by the Connection object. Only the needed parameters are sent, so we can reconstruct the object on the controller side, without serializing everything.

Returns:
an instance of the AbstractWriteRequest
Throws:
java.io.IOException
See Also:
AbstractRequest.AbstractRequest(CJDBCInputStream, int)

setRequestParameters

private boolean setRequestParameters(AbstractRequest request,
                                     java.lang.String login,
                                     long tid,
                                     boolean transactionStarted)
                              throws java.sql.SQLException
Set the login and transaction id on the given request. If the request is autocommit and a transaction was started, the transaction is first commited to return in autocommit mode.

Parameters:
request - The request to set
login - user login to set
tid - the transaction id to set
Returns:
new value of transaction started
Throws:
java.sql.SQLException

putStreamingReferences

private void putStreamingReferences(ControllerResultSet crs,
                                    DriverResultSet drs)
Keep a reference to both ResultSets, but garbage collect data already sent.


run

public void run()
Gets a connection from the connection queue and process it.


close

private void close()
            throws java.io.IOException
Throws:
java.io.IOException

closeRemoteResultSet

private void closeRemoteResultSet()
                           throws java.io.IOException
Throws:
java.io.IOException

reset

private void reset()

restoreConnectionState

private void restoreConnectionState()
                             throws java.io.IOException
Throws:
java.io.IOException

connectionSetCatalog

private void connectionSetCatalog()
                           throws java.io.IOException
Throws:
java.io.IOException

connectionGetCatalog

private void connectionGetCatalog()
                           throws java.io.IOException
Throws:
java.io.IOException

connectionGetCatalogs

private void connectionGetCatalogs()
                            throws java.io.IOException
Throws:
java.io.IOException

connectionSetTransactionIsolation

private void connectionSetTransactionIsolation()
                                        throws java.io.IOException
Throws:
java.io.IOException

databaseMetaDataGetAttributes

private void databaseMetaDataGetAttributes()
                                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getAttributes(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetBestRowIdentifier

private void databaseMetaDataGetBestRowIdentifier()
                                           throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getBestRowIdentifier(java.lang.String, java.lang.String, java.lang.String, int, boolean)

databaseMetaDataGetColumnPrivileges

private void databaseMetaDataGetColumnPrivileges()
                                          throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getColumnPrivileges(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetColumns

private void databaseMetaDataGetColumns()
                                 throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetCrossReference

private void databaseMetaDataGetCrossReference()
                                        throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getCrossReference(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetDatabaseProductName

private void databaseMetaDataGetDatabaseProductName()
                                             throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getDatabaseProductName()

databaseMetaDataGetExportedKeys

private void databaseMetaDataGetExportedKeys()
                                      throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getExportedKeys(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetImportedKeys

private void databaseMetaDataGetImportedKeys()
                                      throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getImportedKeys(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetIndexInfo

private void databaseMetaDataGetIndexInfo()
                                   throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getIndexInfo(java.lang.String, java.lang.String, java.lang.String, boolean, boolean)

databaseMetaDataGetPrimaryKeys

private void databaseMetaDataGetPrimaryKeys()
                                     throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetProcedureColumns

private void databaseMetaDataGetProcedureColumns()
                                          throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getProcedureColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetProcedures

private void databaseMetaDataGetProcedures()
                                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getProcedures(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetSchemas

private void databaseMetaDataGetSchemas()
                                 throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getSchemas()

databaseMetaDataGetSuperTables

private void databaseMetaDataGetSuperTables()
                                     throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getSuperTables(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetSuperTypes

private void databaseMetaDataGetSuperTypes()
                                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getSuperTypes(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetTablePrivileges

private void databaseMetaDataGetTablePrivileges()
                                         throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getTablePrivileges(java.lang.String, java.lang.String, java.lang.String)

databaseMetaDataGetTables

private void databaseMetaDataGetTables()
                                throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getTables(java.lang.String, java.lang.String, java.lang.String, java.lang.String[])

databaseMetaDataGetTableTypes

private void databaseMetaDataGetTableTypes()
                                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getTableTypes()

databaseMetaDataGetTypeInfo

private void databaseMetaDataGetTypeInfo()
                                  throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getTypeInfo()

databaseMetaDataGetUDTs

private void databaseMetaDataGetUDTs()
                              throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getUDTs(java.lang.String, java.lang.String, java.lang.String, int[])

databaseMetaDataGetVersionColumns

private void databaseMetaDataGetVersionColumns()
                                        throws java.io.IOException
Throws:
java.io.IOException
See Also:
DatabaseMetaData.getVersionColumns(java.lang.String, java.lang.String, java.lang.String)

databaseStaticMetadata

private void databaseStaticMetadata()
                             throws java.io.IOException,
                                    NotImplementedException
Get the static metadata key from the socket and return the corresponding metadata.

Throws:
java.io.IOException - if an IO error occurs
NotImplementedException - if the underlying metadata access method is not implemented

getControllerVersionNumber

private void getControllerVersionNumber()
                                 throws java.io.IOException
Throws:
java.io.IOException

getVirtualDatabaseName

private void getVirtualDatabaseName()
                             throws java.io.IOException
Throws:
java.io.IOException

begin

private void begin()
            throws java.sql.SQLException,
                   java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

commit

private void commit()
             throws java.sql.SQLException,
                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

rollback

private void rollback()
               throws java.sql.SQLException,
                      java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setAutoCommit

private void setAutoCommit()
                    throws java.sql.SQLException,
                           java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setNamedSavepoint

private void setNamedSavepoint()
                        throws java.sql.SQLException,
                               java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setUnnamedSavepoint

private void setUnnamedSavepoint()
                          throws java.sql.SQLException,
                                 java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

releaseSavepoint

private void releaseSavepoint()
                       throws java.sql.SQLException,
                              java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

rollbackToSavepoint

private void rollbackToSavepoint()
                          throws java.sql.SQLException,
                                 java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

execReadRequest

private void execReadRequest()
                      throws java.io.IOException,
                             java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

execReadStoredProcedure

private void execReadStoredProcedure()
                              throws java.io.IOException,
                                     java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

execWriteRequest

private void execWriteRequest()
                       throws java.io.IOException,
                              java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

execWriteRequestWithKeys

private void execWriteRequestWithKeys()
                               throws java.io.IOException,
                                      java.sql.SQLException
execWriteRequestWithKeys() will probably have soon no difference with execWriteRequest() anymore; then we can get rid of it.

Throws:
java.io.IOException
java.sql.SQLException

execWriteStoredProcedure

private void execWriteStoredProcedure()
                               throws java.io.IOException,
                                      java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

sendToDriver

private void sendToDriver(DriverResultSet drs)
                   throws java.io.IOException
Serialize a DriverResultSet answer, prefixed with the appropriate TypeTag

Parameters:
drs - the resultset to send
Throws:
java.io.IOException - stream error

sendToDriver

private void sendToDriver(java.lang.String str)
                   throws java.io.IOException
Send a protocol String, prefixed with the appropriate TypeTag

Throws:
java.io.IOException

sendToDriver

private void sendToDriver(boolean b)
                   throws java.io.IOException
Send a protocol boolean, prefixed with the appropriate TypeTag

Throws:
java.io.IOException

sendToDriver

private void sendToDriver(int i)
                   throws java.io.IOException
Send a protocol int, prefixed with the appropriate TypeTag

Throws:
java.io.IOException

sendToDriver

private void sendToDriver(long l)
                   throws java.io.IOException
Send a protocol long, prefixed with the appropriate TypeTag

Throws:
java.io.IOException

sendToDriver

private void sendToDriver(java.lang.Exception e)
                   throws java.io.IOException
Throws:
java.io.IOException

fetchNextResultSetRows

private void fetchNextResultSetRows()
                             throws java.io.IOException,
                                    java.sql.SQLException
Implements streaming: send the next ResultSet chunk to driver, pulling it from ControllerResultSet. The driver decides of the chunk size at each call. Note that virtualdatabase streaming is independent from backend streaming (which may not be supported). They even could be configured with two different fetchSize -s (it's not currently the case).

Throws:
java.io.IOException
java.sql.SQLException
See Also:
AbstractLoadBalancer.executeSelectRequestOnBackend(SelectRequest, org.objectweb.cjdbc.controller.backend.DatabaseBackend, Connection, org.objectweb.cjdbc.controller.cache.metadata.MetadataCache), ControllerResultSet.fetchData(int)

retrieveClientData

public java.lang.String[] retrieveClientData()
Retrieve general information on this client

Returns:
an array of string

getTimeActive

public long getTimeActive()
Get time active

Returns:
time active since started

getUser

public java.lang.String getUser()
Returns:
Returns the login of the current user.

shutdown

public void shutdown()
Shutdown this thread by setting isKilled value to true. This gives time to check for needed rollback transactions



Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.