|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.util.Helper
com.noelios.restlet.ConnectorHelper
com.noelios.restlet.ClientHelper
com.noelios.restlet.ext.jdbc.JdbcClientHelper
public class JdbcClientHelper
Client connector to a JDBC database.
To send a request to the server,
create a new instance of a client supporting the JDBC Protocol and invoke the
handle() method.
Alternatively, you can create a new Call with the JDBC
URI as the resource reference and use an XML request as the entity.
Database connections are optionally pooled using Apache Commons DBCP. In this
case, a different connection pool is created for each unique combination of
JDBC URI and connection properties.
Do not forget to register
your JDBC drivers before using this client. See
JDBC DriverManager API for details
Sample XML request:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<request>
<header>
<connection>
<usePooling>true</usePooling>
<property name="user">scott</property >
<property name="password">tiger</property >
<property name="...">1234</property >
<property name="...">true</property >
</connection>
<returnGeneratedKeys>true</returnGeneratedKeys>
</header>
<body>
<statement>UPDATE myTable SET myField1="value1" </statement>
<statement>SELECT msField1, myField2 FROM myTable</statement>
</body>
</request>
Several SQL
Statements can be specified.
A RowSetRepresentation of the last
correctly executed SQL request is returned to the Client.
RowSetRepresentation
Constructor Summary | |
---|---|
JdbcClientHelper(Client client)
Constructor. |
Method Summary | |
---|---|
static Request |
create(String jdbcURI,
Representation request)
Creates an uniform call. |
protected static org.apache.commons.pool.ObjectPool |
createConnectionPool(String uri,
Properties properties)
Creates a connection pool for a given connection configuration. |
protected Connection |
getConnection(String uri,
Properties properties,
boolean usePooling)
Returns a JDBC connection. |
void |
handle(Request request,
Response response)
Handles a call. |
static String |
sqlEncode(String query)
Escapes quotes in a SQL query. |
Methods inherited from class com.noelios.restlet.ClientHelper |
---|
getClient, getContext, getLogger, getParameters |
Methods inherited from class com.noelios.restlet.ConnectorHelper |
---|
createContext, getProtocols, start, stop |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JdbcClientHelper(Client client)
client
- The client to help.Method Detail |
---|
public static Request create(String jdbcURI, Representation request)
jdbcURI
- The database's JDBC URI (ex:
jdbc:mysql://[hostname]/[database]).request
- The request to send (valid XML request).public void handle(Request request, Response response)
handle
in class ConnectorHelper
request
- The request to handle.response
- The response to update.protected Connection getConnection(String uri, Properties properties, boolean usePooling) throws SQLException
uri
- The connection URI.properties
- The connection properties.usePooling
- Indicates if the connection pooling should be used.
SQLException
public static String sqlEncode(String query)
query
- The SQL query to escape.
protected static org.apache.commons.pool.ObjectPool createConnectionPool(String uri, Properties properties)
uri
- The connection URI.properties
- The connection properties.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |