|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.util.Helper<T>
com.noelios.restlet.ConnectorHelper<Client>
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(java.lang.String jdbcURI,
Representation request)
Creates an uniform call. |
protected static org.apache.commons.pool.ObjectPool |
createConnectionPool(java.lang.String uri,
java.util.Properties properties)
Creates a connection pool for a given connection configuration. |
protected java.sql.Connection |
getConnection(java.lang.String uri,
java.util.Properties properties,
boolean usePooling)
Returns a JDBC connection. |
void |
handle(Request request,
Response response)
Handles a call. |
static java.lang.String |
sqlEncode(java.lang.String query)
Escapes quotes in a SQL query. |
Methods inherited from class com.noelios.restlet.ClientHelper |
---|
getConnectTimeout |
Methods inherited from class com.noelios.restlet.ConnectorHelper |
---|
getProtocols, start, stop, update |
Methods inherited from class org.restlet.util.Helper |
---|
getAttributes, getContext, getHelped, getHelpedParameters, getLogger, setHelped |
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(java.lang.String jdbcURI, Representation request)
jdbcURI
- The database's JDBC URI (ex:
jdbc:mysql://[hostname]/[database]).request
- The request to send (valid XML request).protected static org.apache.commons.pool.ObjectPool createConnectionPool(java.lang.String uri, java.util.Properties properties)
uri
- The connection URI.properties
- The connection properties.
public static java.lang.String sqlEncode(java.lang.String query)
query
- The SQL query to escape.
protected java.sql.Connection getConnection(java.lang.String uri, java.util.Properties properties, boolean usePooling) throws java.sql.SQLException
uri
- The connection URI.properties
- The connection properties.usePooling
- Indicates if the connection pooling should be used.
java.sql.SQLException
public void handle(Request request, Response response)
handle
in class Helper<Client>
request
- The request to handle.response
- The response to update.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |