com.waveset.adapter
Class JdbcResourceAdapter

java.lang.Object
  extended bycom.waveset.adapter.ResourceAdapterBase
      extended bycom.waveset.adapter.JdbcResourceAdapter
All Implemented Interfaces:
ResourceAdapter
Direct Known Subclasses:
DatabaseTableResourceAdapter, ExampleTableResourceAdapter, MIISResourceAdapter, MSSQLServerResourceAdapter, OracleERPResourceAdapter, OracleERPResourceAdapter10_7, OracleResourceAdapter, ScriptedJdbcResourceAdapter, SiteminderExampleTableResourceAdapter, SQLServerResourceAdapter, SybaseResourceAdapter

public abstract class JdbcResourceAdapter
extends ResourceAdapterBase


Nested Class Summary
 
Nested classes inherited from class com.waveset.adapter.ResourceAdapterBase
ResourceAdapterBase.SimpleAccountIterator
 
Nested classes inherited from class com.waveset.adapter.ResourceAdapter
ResourceAdapter.ActionResult, ResourceAdapter.Features, ResourceAdapter.ObjectType
 
Field Summary
static java.lang.String RA_DATABASE
          The name of the database to connect to.
static java.lang.String RA_DRIVER
          The class name of the JDBC driver.
static java.lang.String RA_HOST
          The name of the host used on which the server is listening.
static java.lang.String RA_PASSWORD
          The password for the system account used to access the resource.
static java.lang.String RA_PORT
          The port on which the server is listening.
static java.lang.String RA_QUOTING
          The type of Table Name Quoting to be used in sql for this resource.
static java.lang.String RA_URL_PREFIX
          The JDBC driver url prefix Each driver will have a particular prefix they expect when formatting the url passed to the JDBC getConnection method.
static java.lang.String RA_URL_TEMPLATE
          The JDBC driver url template.
static java.lang.String RA_USER
          The system account name used to access the resource.
 
Fields inherited from class com.waveset.adapter.ResourceAdapterBase
_cache, _context, _excludedAccountsRule, _excludedAccountsRuleInited, _listAllObjectsAttrParse, _listAllObjectsAttrParseName, _listUserAttrParse, _listUserAttrParseName, _listUserGroupsAttrParse, _listUserGroupsAttrParseName, _resource, _thread, _trace, code_id, displayInfoCode, RA_BLOCKCOUNT, RA_LOGIN_ACTION, RA_LOGOFF_ACTION, RA_MULTI_VALUED_ATTRS, RA_TEST_MODE
 
Fields inherited from interface com.waveset.adapter.ResourceAdapter
CHANGE_PASSWORD_LOCATION, DISABLE, ENABLE, EXPIRE_PASSWORD, GUID, IGNORE_ATTR, NEW_ACCOUNT_ID, OP_DAYS_INACTIVE, OP_DISABLED, OP_DORMANT, OP_EXPIRED, OP_EXPIREDPWD, OP_INACTIVE, OP_LOCKED, OP_NO_PASSWORD_SET, OP_NOOWNERSHIP, OP_NOPASSWORDREQ, OP_NUMINACTIVEDAYS, OP_NUMPWDAYS, OP_PWNUMDAYS, RA_BASE_CTX, RA_DISPLAY_NAME_ATTR, RA_NEW_OBJECT_ID, RA_NEW_OBJECT_NAME, RA_OBJECT_ATTRIBUTES, RA_OBJECT_CLASS, RA_OBJECT_ID, RA_OBJECT_TYPE, RA_OP_TYPE, RA_RENAME_OP, RA_REQUESTOR, RA_SAVEAS_OP, RA_SEARCH_ATTRIBUTE_NAMES, RA_SEARCH_ATTRS_TO_GET, RA_SEARCH_CONTEXT, RA_SEARCH_FILTER, RA_SEARCH_RUN_AS_PASSWORD, RA_SEARCH_RUN_AS_USER, RA_SEARCH_SCOPE, RA_SEARCH_SCOPE_OBJECT, RA_SEARCH_SCOPE_ONE_LEVEL, RA_SEARCH_SCOPE_SUBTREE, RA_SEARCH_TIME_LIMIT, RESET_PASSWORD, SYSTEM_ATTRIBUTES, UNLOCK, WS_USER_PASSWORD
 
Constructor Summary
JdbcResourceAdapter()
          Create an adapater instance, without a resource.
JdbcResourceAdapter(Resource res, ObjectCache cache)
          Create an adapter instance for a resource.
 
Method Summary
 void addAttributeValue(java.lang.StringBuffer b, java.lang.String attrValue, java.lang.String attrName)
          Appends attrValue to the end of StringBuffer b, which is most likely an SQL statement.
 void addQuoted(java.lang.StringBuffer b, java.lang.String s)
          Add a quoted string to a SQL statement we're building in a buffer.
protected  boolean attributeRequiresQuotingInSQL(java.lang.String mapName)
          Return true iff the attribute specified by mapName requires quoting when used in SQL.
 void closeConnection(java.sql.Connection con)
          Close a connection, quietly.
 void closeResult(java.sql.ResultSet res)
          Close a result, quietly.
 void closeStatement(java.sql.PreparedStatement stmt)
          Close a statement, quietly.
protected  java.util.List decodeCommaList(java.lang.String src)
          Convert a comma delimited list of names in to a List object.
 void dumpResult(java.sql.ResultSet rs)
          Dump a ResultSet.
protected  java.lang.String encodeCommaList(java.util.List list)
          Convert a list of names into a comma delimited list.
protected  void execProcedure(java.sql.Connection con, java.lang.String stmt)
          Execute a stored procedure that doesn't return a result set.
protected  void execProcedure(java.sql.Connection con, java.lang.String stmt, int ignoreError)
          Execute a stored procedure that doesn't return a result set.
protected  void execSql(java.sql.Connection con, java.lang.String stmt)
          Execute a simple statement, not expected to return a result.
protected  void execSql(java.sql.Connection con, java.lang.String stmt, java.lang.String arg)
          Execute a simple statement, with a SQL argument.
protected  void execSql(java.sql.Connection con, java.lang.String stmt, java.lang.String arg, int ignoreError)
          Execute a simple statement, not expected to return a result, but touch each of them just to be sure and allow a SQLException to shine through.
protected  void flushResults(java.lang.String stmt, java.sql.PreparedStatement st)
          Spin through any results remaining for this statement.
protected  void flushResultsQuietly(java.sql.PreparedStatement st)
          Called to flush any pending results, but not propagate any exceptions.
 java.lang.String formatTemplateUrl(java.lang.String template, java.lang.String database)
          Format a URL given a template.
protected  java.lang.String formatUrl(java.lang.String database)
          Format the connection url
 java.lang.String formatUrl(java.lang.String prefix, java.lang.String host, java.lang.String port, java.lang.String db)
          This is the one used by SQL Server, and I would think it would be standard, but sadly it isnot recognized by Sybase, which has to overload this method to use ":" rather than "://" Should start using URL templates now to avoid these issues.
 java.sql.Connection getConnection()
          Get a connection to the default database with the proxy user.
protected  java.sql.Connection getConnection(java.lang.String database)
          Get a connection to a parciualr database with the proxy user.
protected  java.sql.Connection getConnection(java.lang.String db, java.lang.String user, java.lang.String password)
          Establish a connection to a database using a particular user name and password.
protected  java.lang.String getConnectionString(java.sql.Connection c)
           
protected  java.sql.Connection getConnectionUrl(java.util.HashMap args)
          Obtain a pooled connection.
protected  java.sql.Connection getConnectionUrl(java.lang.String url)
          Obtain a pooled connection.
protected  java.lang.String getEncryptedResourceAttribute(java.lang.String name)
          Get a resource attribute value as a string, carefully.
protected  java.lang.String getResourceAttribute(java.lang.String name)
          Get a resource attribute value as a string, carefully.
protected  java.util.List mergeCommaLists(java.lang.String s1, java.lang.String s2)
          Merge two comma lists together.
protected  java.util.List mergeStringLists(java.util.List l1, java.util.List l2)
          Merge two lists of strings together.
 void println(java.lang.String msg)
           
 int queryInt(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return an expected integer in the first column of the first row.
 java.lang.String queryString(java.sql.Connection c, java.lang.String q, java.lang.String arg)
          Run a query and return an expected string in the first column of the first row.
 void setDebug(boolean b)
           
 
Methods inherited from class com.waveset.adapter.ResourceAdapterBase
authenticate, checkCreateAccount, checkDeleteAccount, checkForNoPasswordInSchema, checkSyntax, checkUpdateAccount, createAccount, createAccounts, createIdentity, createObject, createPrototypeResource, deleteAccount, deleteAccount, deleteAccounts, deleteObject, disableAccount, disableAccounts, dnsEqual, dnsEqual, enableAccount, enableAccounts, executeResourceAttributeJavascriptAction, fillInResourceInfo, fillInResourceInfo, getAccountAttributes, getAccountIterator, getAccountIterator, getAccountIterator, getAction, getActionNotFoundErrorMessage, getActionNotFoundMessage, getActionRunAsPassword, getActionRunAsUser, getActionTimeout, getActionType, getAdapter, getAdapter, getAdapter, getAdapterProxy, getAdapterProxy, getAllAccounts, getAttrNameFromMapName, getAttrNameFromMapName, getAttrParse, getAttrTypeFromMapName, getAttrTypeFromMapName, getAUserName, getBaseContextAttrName, getBaseContextObject, getBaseContexts, getBlockSize, getContext, getExcludedAccountsRule, getFeatures, getIdentity, getListAllObjectsAttrParse, getListUserAttrParse, getListUserGroupsAttrParse, getObject, getOptionalBooleanResAttrVal, getOptionalBooleanResAttrVal, getOptionalEncryptedResAttrVal, getOptionalResAttrVal, getOptionalStringResAttrVal, getRequiredResAttr, getRequiredResAttr, getRequiredResAttrVal, getRequiredResAttrVal, getRequiredResAttrVals, getRequiredUserAttributeNames, getResAttrValActionOnUser, getResAttrVals, getResource, getResourceAccounts, getResourceInfo, getResourceObjectAttrValNameAttr, getResourceObjectClassAttr, getResourceObjectTypePrefix, getSchemaMap, getUser, getUser, getWSAttrByMapName, getWSAttrByMapName, getWSAttrFromMap, handleActionResult, handleJavascriptActionResult, isAccountAttributeSecret, isExcludedAccount, isExcludedAccount, isFeatureEnabled, isSupported, isTestMode, listAllObjects, listAllObjects, listObjects, listObjects, listObjectsOfType, lookupAction, lookupAction, lookupActions, namesEqual, objectClassesMatchType, println, realCreate, realDelete, realDisable, realEnable, realUpdate, restoreResourceObjectClassAttr, run, run, runResourceAttributeJavascriptAction, scan, setCache, setContext, setDisabled, setFromResource, setResource, setResourceObjectClassAttr, setResourceOptionAttrs, startConnection, startConnectionWrapper, stopConnection, supportsAccountActions, supportsAccountDisable, supportsActions, supportsCaseInsensitiveAccountIds, supportsContainerObjectTypes, supportsExcludedAccounts, supportsResourceAccount, supportsScanning, testConfiguration, updateAccount, updateAccounts, updateObject, updateResourceAccount, updateResourceIdentity, vmStoreBoot, vmStoreGet, vmStoreInit, vmStoreLatch, vmStorePut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RA_DRIVER

public static final java.lang.String RA_DRIVER
The class name of the JDBC driver. You do not necessarily need to expose this as a resource attribute, but it can be convenient if you want to evaluate different drivers, or switch between different database vendors.

See Also:
Constant Field Values

RA_URL_PREFIX

public static final java.lang.String RA_URL_PREFIX
The JDBC driver url prefix Each driver will have a particular prefix they expect when formatting the url passed to the JDBC getConnection method. Note, that some drivers also have specific syntax requirements for the remainder of the URL, there doesn't appear to be a universal standard. If you need to switch between drivers from different vendors, you may also need to expose a resource attribute

See Also:
Constant Field Values

RA_URL_TEMPLATE

public static final java.lang.String RA_URL_TEMPLATE
The JDBC driver url template. Used if the driver doesn't support the default template.

See Also:
Constant Field Values

RA_HOST

public static final java.lang.String RA_HOST
The name of the host used on which the server is listening.

See Also:
Constant Field Values

RA_PORT

public static final java.lang.String RA_PORT
The port on which the server is listening.

See Also:
Constant Field Values

RA_DATABASE

public static final java.lang.String RA_DATABASE
The name of the database to connect to. Most systems typically have a single server process listening on a port, that serves as a connection gateway for multiple databases. If the database you're connecting to is implied by the combination of host & port, then you do not need to expose this attribute.

See Also:
Constant Field Values

RA_USER

public static final java.lang.String RA_USER
The system account name used to access the resource. This user must have sufficient privileges to perform the SQL statements embedded in the adapter.

See Also:
Constant Field Values

RA_PASSWORD

public static final java.lang.String RA_PASSWORD
The password for the system account used to access the resource.

See Also:
Constant Field Values

RA_QUOTING

public static final java.lang.String RA_QUOTING
The type of Table Name Quoting to be used in sql for this resource.

See Also:
Constant Field Values
Constructor Detail

JdbcResourceAdapter

public JdbcResourceAdapter(Resource res,
                           ObjectCache cache)
Create an adapter instance for a resource.


JdbcResourceAdapter

public JdbcResourceAdapter()
Create an adapater instance, without a resource.

Method Detail

setDebug

public void setDebug(boolean b)

getResourceAttribute

protected java.lang.String getResourceAttribute(java.lang.String name)
Get a resource attribute value as a string, carefully.


getEncryptedResourceAttribute

protected java.lang.String getEncryptedResourceAttribute(java.lang.String name)
                                                  throws WavesetException
Get a resource attribute value as a string, carefully. Expect it to have encrypted data. If we find a string, assume its an encrypted string. This is a kludge for the current GUI/ResourceAttribute behavior of storing passwords an EncryptedData, but then converting them to strings during XML serialization.

Throws:
WavesetException

attributeRequiresQuotingInSQL

protected boolean attributeRequiresQuotingInSQL(java.lang.String mapName)
Return true iff the attribute specified by mapName requires quoting when used in SQL. It assumes that only integers do not require quoting. For backwards compatibility, this method is conservative as it returns true if nothing is known about the attribute's syntax. Booleans might potentially need quoting, but that might break backward compatiblity. To add support for this change if (syntaxes.contains(Syntax.INT) to if (syntaxes.contains(Syntax.INT) || syntaxes.contains(Syntax.BOOLEAN))


addAttributeValue

public void addAttributeValue(java.lang.StringBuffer b,
                              java.lang.String attrValue,
                              java.lang.String attrName)
Appends attrValue to the end of StringBuffer b, which is most likely an SQL statement. If attrName corresponds to an integer or boolean attribute, then the value is not quoted, otherwise it is.


addQuoted

public void addQuoted(java.lang.StringBuffer b,
                      java.lang.String s)
Add a quoted string to a SQL statement we're building in a buffer. If the attribute might be an integer, then call addAttributeValue() instead, which factors in the syntax of the attribute when determining whether or not to quote the value.


decodeCommaList

protected java.util.List decodeCommaList(java.lang.String src)
Convert a comma delimited list of names in to a List object.


encodeCommaList

protected java.lang.String encodeCommaList(java.util.List list)
Convert a list of names into a comma delimited list.


mergeCommaLists

protected java.util.List mergeCommaLists(java.lang.String s1,
                                         java.lang.String s2)
Merge two comma lists together. Typically used to determine the list of groups (or roles) that an account should have by merging the roles specified in a resource attribute with those specified in an account attribute.


mergeStringLists

protected java.util.List mergeStringLists(java.util.List l1,
                                          java.util.List l2)
Merge two lists of strings together. Typically used to determine the list of groups (or roles) that an account should have by merging the roles specified in a resource attribute with those specified in an account attribute.


getConnection

public java.sql.Connection getConnection()
                                  throws WavesetException
Get a connection to the default database with the proxy user.

Throws:
WavesetException

getConnection

protected java.sql.Connection getConnection(java.lang.String database)
                                     throws WavesetException
Get a connection to a parciualr database with the proxy user.

Throws:
WavesetException

formatUrl

protected java.lang.String formatUrl(java.lang.String database)
                              throws WavesetException
Format the connection url

Throws:
WavesetException

formatUrl

public java.lang.String formatUrl(java.lang.String prefix,
                                  java.lang.String host,
                                  java.lang.String port,
                                  java.lang.String db)
This is the one used by SQL Server, and I would think it would be standard, but sadly it isnot recognized by Sybase, which has to overload this method to use ":" rather than "://" Should start using URL templates now to avoid these issues.


formatTemplateUrl

public java.lang.String formatTemplateUrl(java.lang.String template,
                                          java.lang.String database)
Format a URL given a template. Recognized template characters are: % literal % h host p port d database


getConnectionUrl

protected java.sql.Connection getConnectionUrl(java.lang.String url)
                                        throws WavesetException
Obtain a pooled connection.

Throws:
WavesetException

getConnectionUrl

protected java.sql.Connection getConnectionUrl(java.util.HashMap args)
                                        throws WavesetException
Obtain a pooled connection.

Throws:
WavesetException

getConnection

protected java.sql.Connection getConnection(java.lang.String db,
                                            java.lang.String user,
                                            java.lang.String password)
                                     throws WavesetException
Establish a connection to a database using a particular user name and password. This is used only for pass through authentication, so we don't use pooling.

Throws:
WavesetException

println

public void println(java.lang.String msg)

closeConnection

public void closeConnection(java.sql.Connection con)
Close a connection, quietly.


closeStatement

public void closeStatement(java.sql.PreparedStatement stmt)
Close a statement, quietly.


closeResult

public void closeResult(java.sql.ResultSet res)
Close a result, quietly.


queryInt

public int queryInt(java.sql.Connection c,
                    java.lang.String q,
                    java.lang.String arg)
             throws WavesetException
Run a query and return an expected integer in the first column of the first row.

Throws:
WavesetException

queryString

public java.lang.String queryString(java.sql.Connection c,
                                    java.lang.String q,
                                    java.lang.String arg)
                             throws WavesetException
Run a query and return an expected string in the first column of the first row.

Throws:
WavesetException

execProcedure

protected void execProcedure(java.sql.Connection con,
                             java.lang.String stmt)
                      throws WavesetException
Execute a stored procedure that doesn't return a result set.

Throws:
WavesetException

execProcedure

protected void execProcedure(java.sql.Connection con,
                             java.lang.String stmt,
                             int ignoreError)
                      throws WavesetException
Execute a stored procedure that doesn't return a result set. Ignoring a particular vendor code error.

Throws:
WavesetException

execSql

protected void execSql(java.sql.Connection con,
                       java.lang.String stmt)
                throws WavesetException
Execute a simple statement, not expected to return a result.

Throws:
WavesetException

execSql

protected void execSql(java.sql.Connection con,
                       java.lang.String stmt,
                       java.lang.String arg)
                throws WavesetException
Execute a simple statement, with a SQL argument.

Throws:
WavesetException

execSql

protected void execSql(java.sql.Connection con,
                       java.lang.String stmt,
                       java.lang.String arg,
                       int ignoreError)
                throws WavesetException
Execute a simple statement, not expected to return a result, but touch each of them just to be sure and allow a SQLException to shine through.

Allow a particular vendor code error to be ignored.

Throws:
WavesetException

flushResults

protected void flushResults(java.lang.String stmt,
                            java.sql.PreparedStatement st)
                     throws java.sql.SQLException
Spin through any results remaining for this statement. Be sure to consume all results, and let exceptions thrown by the driver propagate. When executing Sybase stored procedures you frequently don't receive any errors until you touch each result, and there can be many results per procedure call.

In Sybase's case, it seems to be enough just to ask for the result to get the exception thrown, we don't have to look for a result containing an error message.

Note that freetds appeared to have a bug where if you called getResultSet and no more results were available, it would hang, apparently waiting for a network response. This makes it incompatible with the Sun documentation, and unsuitable for use here.

Throws:
java.sql.SQLException

dumpResult

public void dumpResult(java.sql.ResultSet rs)
                throws java.sql.SQLException
Dump a ResultSet.

Throws:
java.sql.SQLException

flushResultsQuietly

protected void flushResultsQuietly(java.sql.PreparedStatement st)
Called to flush any pending results, but not propagate any exceptions. This is used only from exit cleanup code where we're already probably propagating a different exception.


getConnectionString

protected java.lang.String getConnectionString(java.sql.Connection c)