com.noelios.restlet.ext.jdbc
Class JdbcClientHelper

java.lang.Object
  extended by org.restlet.util.Helper<T>
      extended by com.noelios.restlet.ConnectorHelper<Client>
          extended by com.noelios.restlet.ClientHelper
              extended by com.noelios.restlet.ext.jdbc.JdbcClientHelper

public class JdbcClientHelper
extends ClientHelper

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.

Author:
Jerome Louvel, Thierry Boileau
See Also:
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

JdbcClientHelper

public JdbcClientHelper(Client client)
Constructor.

Parameters:
client - The client to help.
Method Detail

create

public static Request create(java.lang.String jdbcURI,
                             Representation request)
Creates an uniform call.

Parameters:
jdbcURI - The database's JDBC URI (ex: jdbc:mysql://[hostname]/[database]).
request - The request to send (valid XML request).

createConnectionPool

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.

Parameters:
uri - The connection URI.
properties - The connection properties.
Returns:
The new connection pool.

sqlEncode

public static java.lang.String sqlEncode(java.lang.String query)
Escapes quotes in a SQL query.

Parameters:
query - The SQL query to escape.
Returns:
The escaped SQL query.

getConnection

protected java.sql.Connection getConnection(java.lang.String uri,
                                            java.util.Properties properties,
                                            boolean usePooling)
                                     throws java.sql.SQLException
Returns a JDBC connection.

Parameters:
uri - The connection URI.
properties - The connection properties.
usePooling - Indicates if the connection pooling should be used.
Returns:
The JDBC connection.
Throws:
java.sql.SQLException

handle

public void handle(Request request,
                   Response response)
Handles a call.

Overrides:
handle in class Helper<Client>
Parameters:
request - The request to handle.
response - The response to update.


Copyright © 2005-2008 Noelios Technologies.