org.objectweb.cjdbc.controller.loadbalancer.singledb
Class SingleDB

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
      extended byorg.objectweb.cjdbc.controller.loadbalancer.singledb.SingleDB

public class SingleDB
extends AbstractLoadBalancer

Single Database request load balancer.

The requests coming from the request controller are directly forwarded to the single backend. This load balancer does not support multiple backends.

Version:
1.0
Author:
Emmanuel Cecchet, Vadim Kassin

Field Summary
private  DatabaseBackend backend
           
private static Trace logger
           
 
Fields inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
parsingGranularity, raidbLevel, vdb
 
Constructor Summary
SingleDB(VirtualDatabase vdb)
          Creates a new SingleDB instance.
 
Method Summary
 void begin(TransactionMarkerMetaData tm)
          Begins a new transaction.
 void commit(TransactionMarkerMetaData tm)
          Commits a transaction.
 void disableBackend(DatabaseBackend db)
          Disables a backend that was previously enabled.
 void enableBackend(DatabaseBackend db)
          Enables a backend that was previously disabled.
 java.sql.ResultSet execReadRequest(SelectRequest request)
          Performs a read request.
 java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
          Call a stored procedure that returns a ResultSet.
 int execWriteRequest(AbstractWriteRequest request)
          Performs a write request on the backend.
 java.sql.ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
          Perform a write request and return a ResultSet containing the auto generated keys.
 int execWriteStoredProcedure(StoredProcedure proc)
          Call a stored procedure that performs an update.
 java.lang.String getInformation()
          Gets information about the request load balancer
 java.lang.String getXmlInformation()
          Get information about the Request Load Balancer in xml
 void rollback(TransactionMarkerMetaData tm)
          Rollbacks a transaction.
 void setWeight(java.lang.String name, int w)
          Associate a weight to a backend identified by its logical name.
 
Methods inherited from class org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer
getParsingGranularity, getRAIDbLevel, setParsingGranularity, setRAIDbLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backend

private DatabaseBackend backend

logger

private static Trace logger
Constructor Detail

SingleDB

public SingleDB(VirtualDatabase vdb)
         throws java.sql.SQLException
Creates a new SingleDB instance.

Parameters:
vdb - the VirtualDatabase this load balancer belongs to
Throws:
java.sql.SQLException - if there is not exactly one backend attached to the VirtualDatabase
Method Detail

execReadRequest

public java.sql.ResultSet execReadRequest(SelectRequest request)
                                   throws java.sql.SQLException
Performs a read request. It is up to the implementation to choose to which backend node(s) this request should be sent.

Specified by:
execReadRequest in class AbstractLoadBalancer
Parameters:
request - an SelectRequest
Returns:
the corresponding java.sql.ResultSet
Throws:
java.sql.SQLException - if an error occurs

execWriteRequest

public int execWriteRequest(AbstractWriteRequest request)
                     throws java.sql.SQLException
Performs a write request on the backend.

Specified by:
execWriteRequest in class AbstractLoadBalancer
Parameters:
request - an AbstractWriteRequest
Returns:
number of rows affected by the request
Throws:
java.sql.SQLException - if an error occurs

execWriteRequestWithKeys

public java.sql.ResultSet execWriteRequestWithKeys(AbstractWriteRequest request)
                                            throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Perform a write request and return a ResultSet containing the auto generated keys.

Specified by:
execWriteRequestWithKeys in class AbstractLoadBalancer
Parameters:
request - an AbstractWriteRequest
Returns:
auto generated keys
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execWriteRequestWithKeys(AbstractWriteRequest)

execReadStoredProcedure

public java.sql.ResultSet execReadStoredProcedure(StoredProcedure proc)
                                           throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that returns a ResultSet.

Specified by:
execReadStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
a java.sql.ResultSet value
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execReadStoredProcedure(org.objectweb.cjdbc.sql.StoredProcedure)

execWriteStoredProcedure

public int execWriteStoredProcedure(StoredProcedure proc)
                             throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Call a stored procedure that performs an update.

Specified by:
execWriteStoredProcedure in class AbstractLoadBalancer
Parameters:
proc - the stored procedure call
Returns:
number of rows affected
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.execWriteStoredProcedure(org.objectweb.cjdbc.sql.StoredProcedure)

begin

public void begin(TransactionMarkerMetaData tm)
           throws java.sql.SQLException
Begins a new transaction.

Specified by:
begin in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

commit

public void commit(TransactionMarkerMetaData tm)
            throws java.sql.SQLException
Commits a transaction.

Specified by:
commit in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

rollback

public void rollback(TransactionMarkerMetaData tm)
              throws java.sql.SQLException
Rollbacks a transaction.

Specified by:
rollback in class AbstractLoadBalancer
Parameters:
tm - the transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs

enableBackend

public void enableBackend(DatabaseBackend db)
                   throws java.sql.SQLException
Enables a backend that was previously disabled. Asks the corresponding connection manager to initialize the connections if needed.

Specified by:
enableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to enable
Throws:
java.sql.SQLException - if an error occurs

disableBackend

public void disableBackend(DatabaseBackend db)
                    throws java.sql.SQLException
Disables a backend that was previously enabled. Asks the corresponding connection manager to finalize the connections if needed.

Specified by:
disableBackend in class AbstractLoadBalancer
Parameters:
db - the database backend to disable
Throws:
java.sql.SQLException - if an error occurs

setWeight

public void setWeight(java.lang.String name,
                      int w)
               throws java.sql.SQLException
Description copied from class: AbstractLoadBalancer
Associate a weight to a backend identified by its logical name.

Overrides:
setWeight in class AbstractLoadBalancer
Parameters:
name - the backend name
w - the weight
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractLoadBalancer.setWeight(String, int)

getInformation

public java.lang.String getInformation()
Gets information about the request load balancer

Specified by:
getInformation in class AbstractLoadBalancer
Returns:
String containing information

getXmlInformation

public java.lang.String getXmlInformation()
Description copied from class: AbstractLoadBalancer
Get information about the Request Load Balancer in xml

Specified by:
getXmlInformation in class AbstractLoadBalancer
Returns:
String containing information, xml formatted
See Also:
AbstractLoadBalancer.getXmlInformation()


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