Instructions for Derby Embedded
-------------------------------

Database Setup
-------------------------------
You can use ij utility in WebSphere to create Derby database, ij can be found in 
$WAS_INSTALL$/derby/bin/embedded or $WAS_INSTALL$/derby/bin/networkserver.
First, uncomment the following line in createTables.sql.
-- CONNECT 'jdbc:derby:D:\oauth2db;create=true';
if you are creating tables in existing Derby database, also remove the create=true parameter. 

Then, execute createTables.sql with ij with the following command.
ij createTables.sql

WebSphere Configuration
-------------------------------
In WebSphere administrative console, go to Resources->JDBC->JDBC Providers. 
* Pick a scope (server is what I used) 
* Click New. Wizard will start. 
* Select: 
    Database Type = Derby. 
    Provider Type: Derby JDBC Provider. 
    Implementation Type: Connection pool data source 
* Click Next. 
* Click Finish. 
* Save the config. 

Go to Resources->JDBC->Data Sources. 
* Pick a scope (server is what I used) 
* Click New. Wizard will start. 
* Set: 
    Data source name: OAuth JDBC Service 
    JNDI Name: jdbc/OAuth2DB 
* Click Next. 
* Select the Derby JDBC Provider we just created.
* Click Next. 
* Set: 
    Database name: <the path to Derby embedded database, i.e D:\oauth2db>
    Container Managed Persistence: Checked 
* Click Next, leave settings unchanged in Setup security alias page
* Click Next, Finish. 
* Save the config. 
You can now test the connection, and the component should work when configured with the JDBC plugins for OAuth. 


Tomcat Configuration
-------------------------------
Copy Derby JDBC drivers to the lib folder of Tomcat installation directory. Derby JDBC drivers can be found at
$WAS_INSTALL$/derby/lib. specifically, you need to copy derby.jar and db2client.jar.

To create a datasource, open context.xml file $CATALINA_HOME$/conf and add datasource declaration 
like the followings:
	<Resource name="jdbc/OAuth2DB" auth="Container" type="javax.sql.DataSource"
               driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
               url="jdbc:derby:D:\oauth2db"/>
Here we assume Derby database is created at D:\oauth2db. Refer to Tomcat documentation for more details. 