Methods Summary |
---|
private void | awaitConnection()
synchronized( this ) {
while( connecting ) {
try {
wait();
}
catch( InterruptedException e ) {
if( connecting ) {
throw new MsqlException(e);
}
}
}
}
|
private void | cleanConnection()
synchronized( this ) {
if( current != null ) {
try {
current.close();
}
catch( SQLException e ) {
e.printStackTrace();
}
current = null;
}
connecting = false;
connection = null;
}
input = null;
output = null;
user = null;
|
public synchronized void | clearWarnings()Sets the SQLWarning chain to null.
warnings = null;
|
public synchronized void | close()Closes this database connection. It will also close any associated
Statement instance.
Exception except = null;
awaitConnection();
if( isClosed() ) {
throw new SQLException("This Connection is already closed.");
}
// Any current statement has ownership of the streams
// We therefore have to close *before* sending data
if( current != null ) {
current.close();
current = null;
}
// Let mSQL know we are closing down and close the output stream
try {
output.writeAsciiString("1");
output.flush();
output.close();
output = null;
}
catch( IOException e ) {
output = null;
except = e;
}
// close the input stream
try {
input.close();
input = null;
}
catch( IOException e ) {
input = null;
except = e;
}
// close the connection
try {
connection.close();
}
catch( IOException e ) {
connection = null;
throw new MsqlException(e);
}
if( except != null ) {
throw new MsqlException(except);
}
|
public void | commit()This is a NO-OP for mSQL. All statements are always auto-committed.
|
private void | connect(java.lang.String host, int port, java.lang.String user)
try {
String tmp;
connection = new Socket(host, port);
input = new MsqlInputStream(connection.getInputStream());
output = new MsqlOutputStream(connection.getOutputStream());
tmp = input.readAsciiString();
// Check for mSQL version
if( tmp.startsWith("0:22:") ) {
version = 2; // version 2.0
}
else if( tmp.startsWith("0:6:") ) {
version = 1; // version 1.0.x
}
else {
throw new SQLException("Unsupported mSQL version.");
}
// Check if user was validated
output.writeAsciiString(user);
tmp = input.readAsciiString();
if( !tmp.startsWith("-100:") ) {
throw new SQLException("Access to server denied.");
}
}
catch( IOException e ) {
cleanConnection();
throw new SQLException("Connection failed.");
}
|
public java.sql.Statement | createStatement()This JDBC method creates an instance of MsqlStatement and
returns it. If there are currently any open MsqlStatement's, it
will close them. Not that mSQL does not provide a way to
interrupt executing statements, so it has to wait for any
pending statements to finish before closing them.
awaitConnection();
synchronized( this ) {
if( current != null ) {
try {
current.close();
}
catch( SQLException e ) {
e.printStackTrace();
}
}
current = new MsqlStatement(this, input, output);
return current;
}
|
public boolean | getAutoCommit()This method always returns true since mSQL is always in auto-commit
mode.
return true;
|
public synchronized java.lang.String | getCatalog()Provides the catalog name. mSQL does not support catalogs,
however.
return catalog;
|
public java.sql.DatabaseMetaData | getMetaData()This method is not yet implemented.
return null;
|
public synchronized int | getTransactionIsolation()
return isolation;
|
public java.lang.String | getUser()
awaitConnection();
return user;
|
public synchronized java.sql.SQLWarning | getWarnings()
return warnings;
|
public synchronized boolean | isClosed()
awaitConnection();
return (connection == null);
|
public boolean | isReadOnly()
return false;
|
public java.lang.String | nativeSQL(java.lang.String sql)This gives the driver an opportunity to turn JDBC compliant SQL
into mSQL specific SQL. My feeling is why bother.
return sql;
|
public java.sql.CallableStatement | prepareCall(java.lang.String sql)Callable statements are not supported by mSQL. This will therefore
always throw an exception.
throw new SQLException("mSQL does not support stored procedures.");
|
public java.sql.PreparedStatement | prepareStatement(java.lang.String sql)Prepared statements are not supported by mSQL. This will
therefore always throw an exception.
throw new SQLException("mSQL does not support prepared statements.");
|
public void | rollback()This method always errors since you cannot rollback an mSQL
transaction.
throw new SQLException("mSQL exception: mSQL does not support " +
"rollbacks.");
|
private void | selectDatabase(java.lang.String database)
String tmp;
try {
output.writeAsciiString("2 " + database);
tmp = input.readAsciiString();
if( tmp.startsWith("-1:") ) {
throw new MsqlException(tmp);
}
}
catch( IOException e ) {
cleanConnection();
throw new MsqlException(e);
}
|
public void | setAutoCommit(boolean b)This method will thrown an exception if you try to turn auto-commit
off since JDBC does not support transactional logic.
if( b ) {
return;
}
throw new SQLException("mSQL must always be auto-commit = true.");
|
public synchronized void | setCatalog(java.lang.String str)Sets the catalog name for this connection. mSQL does not support
catalogs, so this method is a NO-OP.
catalog = str;
|
public void | setReadOnly(boolean b)mSQL does not support read-only mode.
throw new SQLException("mSQL does not support read-only mode.");
|
public synchronized void | setTransactionIsolation(int x)This is not supported by mSQL, thus this is a NO-OP.
isolation = x;
|