|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.csstudio.platform.utility.rdb.RDBUtil
public abstract class RDBUtil
Obtain database connection for various RDB systems.
This utility supports an auto-reconnect feature to handle database
timeouts: getConnection() will test if the connection
is still active. If not, it automatically re-connects.
While this simplifies the code for clients that need to perform transactions
every once in a while over a long run time, the connection test can be
expensive for a short flurry of transactions.
It can therefore be suppressed via setAutoReconnect().
Note that versions 1.6.0 and earlier of this plugin defaulted to turning auto-commit off. Since 1.6.0, it uses the original JDBC default with auto-commit enabled, so code that needs transactions is supposed to disable auto-commit for the transaction, then commit or roll back, and re-enable auto-commit.
This change can cause problems in database dialects that consider it
an error to call commit without specifically disabling auto-commit.
| Nested Class Summary | |
|---|---|
static class |
RDBUtil.Dialect
Database dialect. |
| Constructor Summary | |
|---|---|
protected |
RDBUtil(java.lang.String url,
java.lang.String user,
java.lang.String password,
RDBUtil.Dialect dialect,
boolean autoReconnect)
Constructor for derived classes. |
| Method Summary | |
|---|---|
void |
close()
Close the RDB connection. |
static RDBUtil |
connect(java.lang.String url)
Deprecated. Use the version with autoReconnect: connect(String, boolean) |
static RDBUtil |
connect(java.lang.String url,
boolean autoReconnect)
Connect with only a url. |
static RDBUtil |
connect(java.lang.String url,
java.lang.String user,
java.lang.String password)
Deprecated. Use the version with autoReconnect: connect(String, String, String, boolean) |
static RDBUtil |
connect(java.lang.String url,
java.lang.String user,
java.lang.String password,
boolean autoReconnect)
Connect to the database. |
protected abstract java.sql.Connection |
do_connect(java.lang.String url,
java.lang.String user,
java.lang.String password)
Derived class must implement to create the database connection. |
java.sql.Connection |
getConnection()
Get the JDBC connection. |
protected abstract java.lang.String |
getConnectionTestQuery()
Derived classes must implement this to provide a statement that's suitable for testing the connection state. |
RDBUtil.Dialect |
getDialect()
|
void |
setAutoReconnect(boolean auto_reconnect)
Temporarily disable or later re-enable the auto-reconnect feature. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected RDBUtil(java.lang.String url,
java.lang.String user,
java.lang.String password,
RDBUtil.Dialect dialect,
boolean autoReconnect)
throws java.lang.Exception
url - Database URLuser - ... userpassword - ... passworddialect -
java.lang.Exception - on errorconnect(String, String, String)| Method Detail |
|---|
@Deprecated
public static RDBUtil connect(java.lang.String url)
throws java.lang.Exception
connect(String, boolean)
java.lang.Exception
@Deprecated
public static RDBUtil connect(java.lang.String url,
java.lang.String user,
java.lang.String password)
throws java.lang.Exception
connect(String, String, String, boolean)
java.lang.Exception
public static RDBUtil connect(java.lang.String url,
boolean autoReconnect)
throws java.lang.Exception
url - URLautoReconnect - Handle reconnect?
java.lang.Exception#connect(String, String, String, Boolean)
public static RDBUtil connect(java.lang.String url,
java.lang.String user,
java.lang.String password,
boolean autoReconnect)
throws java.lang.Exception
The URL format depends on the database dialect.
For MySQL resp. Oracle, the formats are:
jdbc:mysql://[host]:[port]/[database]?user=[user]&password=[password]
jdbc:oracle:thin:[user]/[password]@//[host]:[port]/[database]
For Oracle, the port is usually 1521.
url - Database URLuser - User name or null if part of URLpassword - Password or null if part of URLautoReconnect - If true, reconnect to RDB automatically
in case of lost connection
java.lang.Exception - on errorclose()public RDBUtil.Dialect getDialect()
protected abstract java.sql.Connection do_connect(java.lang.String url,
java.lang.String user,
java.lang.String password)
throws java.lang.Exception
url - RDB URLuser - User name or null if part of urlpassword - Password or null if part of url
java.lang.Exception - on error
public void setAutoReconnect(boolean auto_reconnect)
throws java.lang.Exception
auto_reconnect - false to disable, true to re-enable
java.lang.Exception - if this RDBUtil was not created with auto-reconnect support
public java.sql.Connection getConnection()
throws java.lang.Exception
It cannot really distinguish between a connection that was closed on purpose, or one that happens to be closed because of a previous network error that caused this very routine to close the connection and then attempt a re-connect - which failed and left the connection as null.
null: Either a valid connection or an exception.
java.lang.Exception - when necessary re-connection failspublic void close()
protected abstract java.lang.String getConnectionTestQuery()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||