org.drizzle.jdbc.internal.mysql
Class MySQLProtocol

java.lang.Object
  extended by org.drizzle.jdbc.internal.mysql.MySQLProtocol
All Implemented Interfaces:
Protocol

public class MySQLProtocol
extends java.lang.Object
implements Protocol

TODO: refactor, clean up TODO: when should i read up the resultset? TODO: thread safety? TODO: exception handling User: marcuse Date: Jan 14, 2009 Time: 4:06:26 PM


Constructor Summary
MySQLProtocol(java.lang.String host, int port, java.lang.String database, java.lang.String username, java.lang.String password, java.util.Properties info)
          Get a protocol instance
 
Method Summary
 void addToBatch(Query dQuery)
          adds a query to the batch
 void cancelCurrentQuery()
          cancels the current query - clones the current protocol and executes a query using the new connection

thread safe

 void clearBatch()
          clears the current batch
 void close()
          Closes socket and stream readers/writers
 void commit()
          commits the current transaction
 boolean createDB()
          should a database be created if it does not exist ?
 java.util.List<QueryResult> executeBatch()
          executes the batch of queries
 QueryResult executeQuery(Query dQuery)
          executes a query
 QueryResult executeQuery(Query dQuery, java.io.InputStream inputStream)
           
 java.lang.String getDatabase()
          returns the current used database
 SupportedDatabases getDatabaseType()
           
 java.lang.String getHost()
          returns the host
 QueryResult getMoreResults()
           
 java.lang.String getPassword()
          the current password
 int getPort()
          returns the port we are connected to
 boolean getReadonly()
          check if it is possble to execute writing operations on this connection
 java.lang.String getServerVariable(java.lang.String variable)
           
 java.lang.String getServerVersion()
          returns the server version string
 java.lang.String getUsername()
          returns the current connected username
static java.lang.String hexdump(byte[] buffer, int offset)
           
static java.lang.String hexdump(java.nio.ByteBuffer bb, int offset)
           
 boolean isClosed()
          returns true if the connection has been closed
 boolean ping()
          checks whether the connectiion is still valid
 void releaseSavepoint(java.lang.String savepoint)
          releases the savepoint
 void rollback()
          rolls back the current transaction
 void rollback(java.lang.String savepoint)
          rolls back to the given save point
 void selectDB(java.lang.String database)
          selects what database to use
 void setReadonly(boolean readOnly)
          sets whether this connection should be read only

TODO: actually enforce this

 void setSavepoint(java.lang.String savepoint)
          sets a save point
 java.util.List<RawPacket> startBinlogDump(int startPos, java.lang.String filename)
           
 boolean supportsPBMS()
           
 void timeOut()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLProtocol

public MySQLProtocol(java.lang.String host,
                     int port,
                     java.lang.String database,
                     java.lang.String username,
                     java.lang.String password,
                     java.util.Properties info)
              throws QueryException
Get a protocol instance

Parameters:
host - the host to connect to
port - the port to connect to
database - the initial database
username - the username
password - the password
info -
Throws:
QueryException - if there is a problem reading / sending the packets
Method Detail

close

public void close()
           throws QueryException
Closes socket and stream readers/writers

Specified by:
close in interface Protocol
Throws:
QueryException - if the socket or readers/writes cannot be closed

isClosed

public boolean isClosed()
Description copied from interface: Protocol
returns true if the connection has been closed

Specified by:
isClosed in interface Protocol
Returns:
true if the connection is closed

selectDB

public void selectDB(java.lang.String database)
              throws QueryException
Description copied from interface: Protocol
selects what database to use

Specified by:
selectDB in interface Protocol
Parameters:
database - the database
Throws:
QueryException - if there is a problem selecting the database

getServerVersion

public java.lang.String getServerVersion()
Description copied from interface: Protocol
returns the server version string

Specified by:
getServerVersion in interface Protocol
Returns:

setReadonly

public void setReadonly(boolean readOnly)
Description copied from interface: Protocol
sets whether this connection should be read only

TODO: actually enforce this

Specified by:
setReadonly in interface Protocol
Parameters:
readOnly - if the connection should be read only

getReadonly

public boolean getReadonly()
Description copied from interface: Protocol
check if it is possble to execute writing operations on this connection

Specified by:
getReadonly in interface Protocol
Returns:
true if we can update etc

commit

public void commit()
            throws QueryException
Description copied from interface: Protocol
commits the current transaction

Specified by:
commit in interface Protocol
Throws:
QueryException - if there is a problem committing the txn

rollback

public void rollback()
              throws QueryException
Description copied from interface: Protocol
rolls back the current transaction

Specified by:
rollback in interface Protocol
Throws:
QueryException - if there is a problem rolling back

rollback

public void rollback(java.lang.String savepoint)
              throws QueryException
Description copied from interface: Protocol
rolls back to the given save point

Specified by:
rollback in interface Protocol
Parameters:
savepoint - the save point to roll back to
Throws:
QueryException - if there is a problem rolling back

setSavepoint

public void setSavepoint(java.lang.String savepoint)
                  throws QueryException
Description copied from interface: Protocol
sets a save point

Specified by:
setSavepoint in interface Protocol
Parameters:
savepoint - the save point name
Throws:
QueryException - if there is a problem setting the save point

releaseSavepoint

public void releaseSavepoint(java.lang.String savepoint)
                      throws QueryException
Description copied from interface: Protocol
releases the savepoint

Specified by:
releaseSavepoint in interface Protocol
Parameters:
savepoint - the name of the savepoint to release
Throws:
QueryException - if there is a problem releasing the save point

getHost

public java.lang.String getHost()
Description copied from interface: Protocol
returns the host

Specified by:
getHost in interface Protocol
Returns:
the host we are connected to

getPort

public int getPort()
Description copied from interface: Protocol
returns the port we are connected to

Specified by:
getPort in interface Protocol
Returns:
the port

getDatabase

public java.lang.String getDatabase()
Description copied from interface: Protocol
returns the current used database

Specified by:
getDatabase in interface Protocol
Returns:

getUsername

public java.lang.String getUsername()
Description copied from interface: Protocol
returns the current connected username

Specified by:
getUsername in interface Protocol
Returns:
the username

getPassword

public java.lang.String getPassword()
Description copied from interface: Protocol
the current password

Specified by:
getPassword in interface Protocol
Returns:
the password

ping

public boolean ping()
             throws QueryException
Description copied from interface: Protocol
checks whether the connectiion is still valid

Specified by:
ping in interface Protocol
Returns:
true if it is valid
Throws:
QueryException - if there is a problem communicating

executeQuery

public QueryResult executeQuery(Query dQuery)
                         throws QueryException
Description copied from interface: Protocol
executes a query

Specified by:
executeQuery in interface Protocol
Parameters:
dQuery - the query to execute
Returns:
a query result.
Throws:
QueryException - if there is a problem with the query

addToBatch

public void addToBatch(Query dQuery)
Description copied from interface: Protocol
adds a query to the batch

Specified by:
addToBatch in interface Protocol
Parameters:
dQuery - the query to add

executeBatch

public java.util.List<QueryResult> executeBatch()
                                         throws QueryException
Description copied from interface: Protocol
executes the batch of queries

Specified by:
executeBatch in interface Protocol
Returns:
a list of query results
Throws:
QueryException - if there is a problem

clearBatch

public void clearBatch()
Description copied from interface: Protocol
clears the current batch

Specified by:
clearBatch in interface Protocol

startBinlogDump

public java.util.List<RawPacket> startBinlogDump(int startPos,
                                                 java.lang.String filename)
                                          throws BinlogDumpException
Specified by:
startBinlogDump in interface Protocol
Throws:
BinlogDumpException

getDatabaseType

public SupportedDatabases getDatabaseType()
Specified by:
getDatabaseType in interface Protocol

supportsPBMS

public boolean supportsPBMS()
Specified by:
supportsPBMS in interface Protocol

getServerVariable

public java.lang.String getServerVariable(java.lang.String variable)
                                   throws QueryException
Specified by:
getServerVariable in interface Protocol
Throws:
QueryException

executeQuery

public QueryResult executeQuery(Query dQuery,
                                java.io.InputStream inputStream)
                         throws QueryException
Specified by:
executeQuery in interface Protocol
Throws:
QueryException

cancelCurrentQuery

public void cancelCurrentQuery()
                        throws QueryException
cancels the current query - clones the current protocol and executes a query using the new connection

thread safe

Specified by:
cancelCurrentQuery in interface Protocol
Throws:
QueryException

timeOut

public void timeOut()
             throws QueryException
Specified by:
timeOut in interface Protocol
Throws:
QueryException

createDB

public boolean createDB()
Description copied from interface: Protocol
should a database be created if it does not exist ?

Specified by:
createDB in interface Protocol

getMoreResults

public QueryResult getMoreResults()
                           throws QueryException
Specified by:
getMoreResults in interface Protocol
Throws:
QueryException

hexdump

public static java.lang.String hexdump(byte[] buffer,
                                       int offset)

hexdump

public static java.lang.String hexdump(java.nio.ByteBuffer bb,
                                       int offset)


Copyright © 2012. All Rights Reserved.