com.sage.orion.sdata.servlet
Class JDBCResourceKind

java.lang.Object
  extended by com.sage.orion.sdata.servlet.JDBCResourceKind
All Implemented Interfaces:
ResourceKind
Direct Known Subclasses:
MockJDBCResourceKind, PagesResourceKind, PortletCategoriesResourceKind, PortletsAndCategoriesResourceKind, ShortCutsResourceKind, TestJDBCResourceKindImpl, UIContentResourceKind, UIDefinitionResourceKind

public abstract class JDBCResourceKind
extends java.lang.Object
implements ResourceKind

An abstract class that handles generic functionalities in favor of it's implementors. It handles the JDBC resource requests ,to avoid SQL injection attacks it uses bind variables in the Java's PreparedStatement


Nested Class Summary
static class JDBCResourceKind.HTTPMethodsAuthorizator
          The HTTPMethodsAuthorizator is used to check whether the ResourceKind supports the specific HTTP method.
static class JDBCResourceKind.ResourceAuthorizator
          The ResourceAuthorizator is used to check whether the user has the privilege to manipulate the ResourceKind.
static class JDBCResourceKind.ResourceDataAuthorizator
          The ResourceDataAuthorizator is used to check whether the user has the privilege to manipulate the specific data of the ResourceKind specified in the request.
 
Field Summary
protected static java.lang.String ADD
           
protected static java.lang.String ALTER_TABLE
           
protected static java.lang.String AND
           
protected static java.lang.String CLOSE_BRACE
           
protected static java.lang.String COMMA
           
protected static java.lang.String CONSTRAINT
           
protected static java.lang.String DEFAULT
           
static java.lang.String DEFAULT_LANGUAGE_CODE
           
protected static java.lang.String DELETE_FROM
           
protected static java.lang.String DROP
           
protected static java.lang.String DROP_TABLE
           
protected static java.lang.String FROM
           
protected static java.lang.String NOT_NULL
           
protected static java.lang.String OPEN_BRACE
           
protected static java.lang.String PRIMARY_KEY
           
protected static java.lang.String SELECT
           
protected static java.lang.String UICONTENT_SQL_SELECT_STMT
           
protected static java.lang.String VARCHAR_50
           
protected static java.lang.String WHERE
           
 
Constructor Summary
JDBCResourceKind(ApplicationContext applicationContext, IConnectionPool connectionPool, java.lang.String authToken)
          Constructor
 
Method Summary
protected  void addCompanyIDField(java.lang.String defaultCompanyID, java.sql.Connection connection)
          Takes the set of records of the default company and creates a new sets for each company registered in Accpac
protected  void addRecordsForAllCompanies(java.lang.String defaultCompanyID, java.sql.Connection connection)
          Takes the set of records of the default company and creates a new sets for each company registered in Accpac
protected  java.lang.String buildUserFilter(java.lang.String exsitingFilter)
          Returns a that contains the existing filter plus a filter by user ID if that the resource is user-specific and the user is a non-ADMIN user, or just the existing filter for all other cases.
 boolean canDelete(UserInfo user, java.sql.Connection connection)
          Indicates whether the user has the privilege to do DELETE against the ResourceKind.
protected  boolean canDeleteOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to DELETE the data specified in the request.
 boolean canGet(UserInfo user, java.sql.Connection connection)
          Indicates whether the user has the privilege to do GET against the ResourceKind.
protected  boolean canGetOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to GET the data specified in the request.
 boolean canPost(UserInfo user, java.sql.Connection connection)
          Indicates whether the user has the privilege to do POST against the ResourceKind.
protected  boolean canPostOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to POST the data specified in the request.
 boolean canPut(UserInfo user, java.sql.Connection connection)
          Indicates whether the user has the privilege to do PUT against the ResourceKind.
protected  boolean canPutOnData(SDataRequest request, java.sql.Connection connection)
          Indicates whether the user has the privilege to PUT the data specified in the request.
protected  java.sql.PreparedStatement createPreparedEntryGetStatement(java.sql.Connection connection, ResourceElement finalResourceElement)
          Form the prepared statement so that we can use it for entry request handling with or without navigation
protected  ResourceResponse doDelete(SDataRequest request, java.sql.Connection connection)
          Handles the Delete operation
protected  ResourceResponse doGet(SDataRequest request, java.sql.Connection connection)
          This method takes appropriate action and generates ResourceResponse based on the specified request
protected  ResourceResponse doPost(SDataRequest request, java.sql.Connection connection)
          Handles the POST request, which is for inserting records.
protected  ResourceResponse doPut(SDataRequest request, java.sql.Connection connection)
          Handles the PUT request, which is for updating records.
protected  SchemaResponse doSchema(SDataRequest request, java.sql.Connection connection)
          Handles the GET request for the special $schema operator.
protected  ResourceResponse doTemplate(SDataRequest request, java.sql.Connection connection)
          Handles the GET request for the special $template operator.
protected  SDataResourceElement fillResultSetResourceElement(java.util.List<java.lang.String> selectCriteria, java.sql.ResultSet resultSet, SDataRequest request)
          Fills a newly created element with the tuple values got from the result set
protected  java.lang.String findUIContentTextValueInDB(java.lang.String textId, java.lang.String language)
           Looks in the UI content table for (and returns if found) the associated text value based on the specified text ID and language and using the specified opened prepared statement, falling back to the default language if such a value was not found in the original language to search for, and returning "" if no such value was found even after fallback.
protected  void focusOnResultSet(ResourceElement resourceElement, java.sql.ResultSet resultSet)
          This routine focus the result set to the particular tuple specified by the key in the URL(predicateKay,Navigation)
protected  void freeConnection(java.sql.Connection connection)
          Free the connection in connection pool.
protected abstract  java.util.List<FieldDefinition> getAllFields()
          returns a list of FieldDefinitions in the ResourceKind
protected  ApplicationContext getApplicationContext()
          Gets the ApplicationContext.
protected  java.lang.String getAuthToken()
          Gets the JDBCResource kinds authentication token.
protected abstract  java.lang.String getCalculateFieldValue(java.lang.String value, SDataRequest request, java.sql.ResultSet resultSet, int fieldIndex)
          Get the value of the calculated field, if it is a regular (non-calculated) field then the original value will be returned unchanged
protected  java.util.Map<java.lang.String,java.lang.String> getCaseInsensitiveColumns()
          Gets the map that contains column names in lower case as key and column names in correct case as value
protected  java.lang.String getColumnNamesFromList(java.util.ArrayList<java.lang.String> columnList)
          This method takes an array of column names and appends them in to one string with commas separating the names.
protected  java.lang.String getCompanyIDField()
          Gets the company id field name in the table/xml.
protected  java.lang.String getCompanyIDForFilter()
          Gets the company id used in the filter for retrieving the data related to the current company.
protected  java.sql.Connection getConnection()
           Gets a JDBC connection from the underlying connection pool associated with the resource kind.
protected  SDataRequest getCurrentRequest()
          Gets the current request.
 UserInfo getCurrentUser()
          Gets the current signed on user.
protected  java.lang.String getCustomizedQuery()
          Get the customized SQL query if need to used instead of default query build by JDBCResourceKind
protected  JDBCDatabaseType getDatabaseType()
          Gets the type of database that the resource kind's current connection is using.
protected  int getDefaultFeedCount()
          Gets the default number of entries to be returned by the resource kind.
protected  SDataResourceElement getFieldData(SDataRequest request, java.sql.ResultSet resultSet, int fieldIndex)
          Get the specified field's data from the resultSet and packs the data in SDataResourceElement
protected  boolean getFieldSchemaIdentity(int index)
          Get the identity from schema, returns an identity of the field from the resourceKind schema definition for the given index.
protected  java.lang.String getFieldSchemaName(int index)
          Get the field name from schema, returns a name of the field from the resourceKind schema definition for the given index.
protected  FieldDataType getFieldSchemaType(int index)
          Get the field type from schema, returns a type of the field from the resourceKind schema definition for the given index.
protected  java.util.ArrayList<java.lang.String> getIncludeColumns()
          Get the columns of the JDBC table that needs to be included
 java.lang.String getInstance()
          
protected  java.lang.String getKeyValueForKeyName(java.sql.ResultSet resultSet)
          Gets the key field value for the primary key(composite keys) from the result set
protected  int getMaxFeedCount()
          Gets the maximum number of entries to be returned by the resource kind.
protected  java.lang.String getOrderByClause(java.util.List<OrderByParameter> orderByParameters)
          Gets a string of the form "SEG1 desc,SEG2,SEG3 desc" for the given orderByParameters
protected  java.lang.String getOrderByClauseForKeyField(boolean ascending)
          Gets a string of the form "SEG1 desc,SEG2,SEG3 desc" for the primary key(composite key)
protected  java.sql.PreparedStatement getPreparedStatement(java.sql.Connection connection, java.lang.String topRowCount, java.lang.String columnNames, java.lang.String filter, java.lang.String orderBy, BindVariables bindVariables, int resultSetType, int resultSetConcurrency)
          Get a PreparedStatement for the SELECT query with the given criteria and set the filter bind variables of the value
protected abstract  java.lang.String[] getPrimaryKey()
          Get the primary key of the underlying JDBC table for which one JDBCResourceKindImpl is created
protected  java.lang.String getQueryStringForParam(java.sql.Connection connection, java.lang.String tableName, java.lang.String topRowCount, java.lang.String columnNames, java.lang.String filter, java.lang.String orderBy)
          Get a query string that can be supplied to an RDBMS SQL query processing engine
protected  int getResourceKindFieldsCount()
          returns a number of fields in the ResourceKind
protected  ResourceResponse getResultRecordAndCreateResponse(java.sql.PreparedStatement prepareResultRecordGet, int httpResponseCode, SDataRequest request)
           Gets a result set with the lone record as specified by the prepared statement, then creates an SData response for that lone record.
protected  SDataSchema getSchema()
          Get the SDataSchema which has the functionality to convert the underlying JDBC table's meta data into text(xml) form so that it can be transmitted over wire
protected abstract  java.lang.String getTableName()
          Get the JDBC table name for which ResourceKindImpl is created
protected  SDataResponseEntry getTemplate(SDataRequest request, java.sql.Connection connection)
           Gets the SData response entry for a GET request for the special $template operator.
protected  java.lang.String getTransText(java.lang.String textId)
           Returns translated value on the string.
protected  java.lang.String getUserIDField()
          Gets the user id field name in the table/xml.
protected  java.lang.String getUserIDForFilter()
          Gets the user id used in the filter for retrieving the data related to the current signed on user.
 ResourceResponse handleRequest(SDataRequest request, AsyncStatusListener listener)
          Handle the specified request, passing information to the listener if there is one.
abstract  boolean isUserSpecificResource()
          Indicates whether the resource is user specific or not.
protected  void maintainTable(ApplicationContext context, java.sql.Connection connection, java.lang.String xmlFileName, java.util.List<FieldDefinition> allTableFields, java.lang.String defaultKeys, java.lang.String defaultCompanyID)
          maintain the database table used by this resource kind.
protected  boolean moveRecordPointerToKeyInURL(java.lang.String keyInURL, java.sql.ResultSet resultSet)
           
 boolean requiresCompanyIdInjection()
          Override and return true if the companyId is required and is provided by server not clients.
protected  boolean requiresSignon()
          Indicates whether the user needs to sign on in order to access the resource kind.
 boolean requiresUserIdInjection()
          Override and return true if the userId is required and is provided by server not clients.
 void shutdown()
          Shut down the resource kind.
protected static java.lang.String[] splitKeyIntoSegments(java.lang.String key, java.lang.String delimiter)
          Split the key into array for the given delimiter
static java.lang.String[] splitResourceSelectorKeyIntoSegments(java.lang.String key)
          Form a string array say {'1','1','3'} from the input URL say (...(1;1;3))
protected abstract  boolean supportDelete()
          Indicates whether the ResourceKind in general supports DELETE or not.
protected abstract  boolean supportGet()
          Indicates whether the ResourceKind in general supports GET or not.
protected abstract  boolean supportPost()
          Indicates whether the ResourceKind in general supports POST or not.
protected abstract  boolean supportPut()
          Indicates whether the ResourceKind in general supports PUT or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sage.orion.sdata.servlet.ResourceKind
getName
 

Field Detail

COMMA

protected static final java.lang.String COMMA
See Also:
Constant Field Values

DELETE_FROM

protected static final java.lang.String DELETE_FROM
See Also:
Constant Field Values

SELECT

protected static final java.lang.String SELECT
See Also:
Constant Field Values

FROM

protected static final java.lang.String FROM
See Also:
Constant Field Values

WHERE

protected static final java.lang.String WHERE
See Also:
Constant Field Values

AND

protected static final java.lang.String AND
See Also:
Constant Field Values

ALTER_TABLE

protected static final java.lang.String ALTER_TABLE
See Also:
Constant Field Values

ADD

protected static final java.lang.String ADD
See Also:
Constant Field Values

PRIMARY_KEY

protected static final java.lang.String PRIMARY_KEY
See Also:
Constant Field Values

DROP

protected static final java.lang.String DROP
See Also:
Constant Field Values

CONSTRAINT

protected static final java.lang.String CONSTRAINT
See Also:
Constant Field Values

OPEN_BRACE

protected static final java.lang.String OPEN_BRACE
See Also:
Constant Field Values

CLOSE_BRACE

protected static final java.lang.String CLOSE_BRACE
See Also:
Constant Field Values

VARCHAR_50

protected static final java.lang.String VARCHAR_50
See Also:
Constant Field Values

DEFAULT

protected static final java.lang.String DEFAULT
See Also:
Constant Field Values

NOT_NULL

protected static final java.lang.String NOT_NULL
See Also:
Constant Field Values

DROP_TABLE

protected static final java.lang.String DROP_TABLE
See Also:
Constant Field Values

DEFAULT_LANGUAGE_CODE

public static final java.lang.String DEFAULT_LANGUAGE_CODE
See Also:
Constant Field Values

UICONTENT_SQL_SELECT_STMT

protected static final java.lang.String UICONTENT_SQL_SELECT_STMT
See Also:
Constant Field Values
Constructor Detail

JDBCResourceKind

public JDBCResourceKind(ApplicationContext applicationContext,
                        IConnectionPool connectionPool,
                        java.lang.String authToken)
Constructor

Parameters:
applicationContext - ApplicationContext
connectionPool - ConnectionPool that is used to access the underlying DB
authToken - the authentication token.
Method Detail

getInstance

public java.lang.String getInstance()

Specified by:
getInstance in interface ResourceKind

shutdown

public void shutdown()
Shut down the resource kind. Note that this may be called on a shutdown thread even though a different thread is executing ResourceKind.handleRequest(SDataRequest, AsyncStatusListener).

Specified by:
shutdown in interface ResourceKind

getTableName

protected abstract java.lang.String getTableName()
Get the JDBC table name for which ResourceKindImpl is created

Returns:
the JDBC table name

getFieldSchemaName

protected java.lang.String getFieldSchemaName(int index)
Get the field name from schema, returns a name of the field from the resourceKind schema definition for the given index.

Parameters:
index - name of the field
Returns:
name FieldSchemaName

getFieldSchemaType

protected FieldDataType getFieldSchemaType(int index)
Get the field type from schema, returns a type of the field from the resourceKind schema definition for the given index.

Parameters:
index - index of the field
Returns:
type FieldSchemaType

getFieldSchemaIdentity

protected boolean getFieldSchemaIdentity(int index)
Get the identity from schema, returns an identity of the field from the resourceKind schema definition for the given index.

Parameters:
index - identity of the field
Returns:
identity FieldSchemaIdentity

getResourceKindFieldsCount

protected int getResourceKindFieldsCount()
returns a number of fields in the ResourceKind

Returns:
fields count

getAllFields

protected abstract java.util.List<FieldDefinition> getAllFields()
returns a list of FieldDefinitions in the ResourceKind

Returns:
FieldDefinition list

getPrimaryKey

protected abstract java.lang.String[] getPrimaryKey()
Get the primary key of the underlying JDBC table for which one JDBCResourceKindImpl is created

Returns:
the primary key

getCalculateFieldValue

protected abstract java.lang.String getCalculateFieldValue(java.lang.String value,
                                                           SDataRequest request,
                                                           java.sql.ResultSet resultSet,
                                                           int fieldIndex)
Get the value of the calculated field, if it is a regular (non-calculated) field then the original value will be returned unchanged

Parameters:
value - value of the field
request - the input SDataRequest
resultSet - resultSet returned by query
fieldIndex - fieldIndex - 0-based
Returns:
the value of the field

getIncludeColumns

protected java.util.ArrayList<java.lang.String> getIncludeColumns()
Get the columns of the JDBC table that needs to be included

Returns:
the list of column names that needs to be included in the result set

getCustomizedQuery

protected java.lang.String getCustomizedQuery()
Get the customized SQL query if need to used instead of default query build by JDBCResourceKind

Returns:
the customized SQL query

handleRequest

public ResourceResponse handleRequest(SDataRequest request,
                                      AsyncStatusListener listener)
Handle the specified request, passing information to the listener if there is one.

Note that even if an implementation is not thread-safe it must allow for the ResourceKind.shutdown() call to execute in parallel.

Specified by:
handleRequest in interface ResourceKind
Parameters:
request - the request to handle
listener - null or a listener than can be used for asynchronous tasks to monitor progress.
Returns:
a ResourceResponse to the request

doSchema

protected SchemaResponse doSchema(SDataRequest request,
                                  java.sql.Connection connection)
Handles the GET request for the special $schema operator.

Parameters:
request - The input SDataRequest for the GET of the special $schema operator.
connection - The JDBC connection object which provides a gateway to access underlying DB.
Returns:
The SData response containing the schema for that resource kind.

getSchema

protected SDataSchema getSchema()
Get the SDataSchema which has the functionality to convert the underlying JDBC table's meta data into text(xml) form so that it can be transmitted over wire

Returns:
A SDataSchema object

doTemplate

protected ResourceResponse doTemplate(SDataRequest request,
                                      java.sql.Connection connection)
                               throws java.sql.SQLException
Handles the GET request for the special $template operator.

Parameters:
request - The input SDataRequest for the GET of the special $template operator.
connection - The JDBC connection object which provides a gateway to access underlying DB.
Returns:
The SData response containing the template entry (think of it as a "new record" buffer with blank defaults).
Throws:
java.sql.SQLException - SQLException

getTemplate

protected SDataResponseEntry getTemplate(SDataRequest request,
                                         java.sql.Connection connection)
                                  throws java.sql.SQLException

Gets the SData response entry for a GET request for the special $template operator.

The default implementation returns an entry whose payload contains a resource entity that has none of its properties (fields) set and does not contain a key (as the default implementation assumes that the key is not set until the insertion happens).

Parameters:
request - the input SDataRequest for the GET of the special $template operator.
connection - The JDBC connection object which provides a gateway to access underlying DB.
Returns:
The SData response entry for a GET request for the special $template operator.
Throws:
java.sql.SQLException - SQLException

doGet

protected ResourceResponse doGet(SDataRequest request,
                                 java.sql.Connection connection)
                          throws java.sql.SQLException
This method takes appropriate action and generates ResourceResponse based on the specified request

Parameters:
request - the SDataRequest
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
The ResourceResponse
Throws:
java.sql.SQLException - SQLException

doPost

protected ResourceResponse doPost(SDataRequest request,
                                  java.sql.Connection connection)
                           throws java.sql.SQLException
Handles the POST request, which is for inserting records. Normally a POST web request is used to submit huge amount of data/secret data in the form of a Stream say ByteStream

Parameters:
request - the request Object having the entry object for the JDBC ResourceKind Post request
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
A ResourceResponse which is a Java object and having the ability to be added into the web(HttpServletResponse) response (addToResponse)
Throws:
java.sql.SQLException - SQLException

doPut

protected ResourceResponse doPut(SDataRequest request,
                                 java.sql.Connection connection)
                          throws java.sql.SQLException
Handles the PUT request, which is for updating records. Normally a Put web request is used to submit huge amount of data/secret data in the form of a Stream say ByteStream

Parameters:
request - the request Object having the entry object for the JDBC ResourceKind Put request
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
A ResourceResponse which is a Java object and having the ability to be added into the web(HttpServletResponse) response (addToResponse)
Throws:
java.sql.SQLException - SQLException

doDelete

protected ResourceResponse doDelete(SDataRequest request,
                                    java.sql.Connection connection)
                             throws java.sql.SQLException
Handles the Delete operation

Parameters:
request - the request having the key for the record identity
connection - the JDBC connection object which provides a gateway to access underlying DB
Returns:
A ResourceResponse which is a Java object and having the ability to be added into the web(HttpServletResponse) response (addToResponse)
Throws:
java.sql.SQLException - SQLException

getResultRecordAndCreateResponse

protected ResourceResponse getResultRecordAndCreateResponse(java.sql.PreparedStatement prepareResultRecordGet,
                                                            int httpResponseCode,
                                                            SDataRequest request)
                                                     throws java.sql.SQLException

Gets a result set with the lone record as specified by the prepared statement, then creates an SData response for that lone record. The response's HTTP response code and resources URL are as specified.

This is intended for use when inserting or updating a record, as the SData specification requires that the response contain the inserted or updated record (where the record includes any automatic changes such as auto-generated key fields).

Parameters:
prepareResultRecordGet - The prepared statement for getting that result set that contains a single record (basically the inserted or updated record).
httpResponseCode - The HTTP response code to use.
request - The originating SData request.
Returns:
The SData response for the lone record retrieved from running the prepared statement. The response's HTTP response code and resources URL are as specified.
Throws:
java.sql.SQLException - SQLException

createPreparedEntryGetStatement

protected java.sql.PreparedStatement createPreparedEntryGetStatement(java.sql.Connection connection,
                                                                     ResourceElement finalResourceElement)
                                                              throws java.sql.SQLException
Form the prepared statement so that we can use it for entry request handling with or without navigation

Parameters:
connection - the JDBC connection object
finalResourceElement - the last resourceElement in the request URL
Returns:
A java's prepared statement having set it's SQL statement and bindVariables if any
Throws:
java.sql.SQLException - SQLException

focusOnResultSet

protected void focusOnResultSet(ResourceElement resourceElement,
                                java.sql.ResultSet resultSet)
                         throws java.sql.SQLException
This routine focus the result set to the particular tuple specified by the key in the URL(predicateKay,Navigation)

Parameters:
resourceElement - the last resource element
resultSet - the result set on which the operation is to be performed
Throws:
java.sql.SQLException - SQLException

fillResultSetResourceElement

protected SDataResourceElement fillResultSetResourceElement(java.util.List<java.lang.String> selectCriteria,
                                                            java.sql.ResultSet resultSet,
                                                            SDataRequest request)
                                                     throws java.sql.SQLException
Fills a newly created element with the tuple values got from the result set

Parameters:
selectCriteria - the list of columns to be included
resultSet - the Java's result set which exposes tuples' data
request - SDataRequest request
Returns:
An SDataResourceElement
Throws:
java.sql.SQLException - SQLException

getFieldData

protected SDataResourceElement getFieldData(SDataRequest request,
                                            java.sql.ResultSet resultSet,
                                            int fieldIndex)
                                     throws java.sql.SQLException
Get the specified field's data from the resultSet and packs the data in SDataResourceElement

Parameters:
request - SDataRequest request
resultSet - the result set from which the specified field data is retrieved
fieldIndex - the index of the field
Returns:
An SDataResourceElement for the specified field index
Throws:
java.sql.SQLException - SQLException

buildUserFilter

protected java.lang.String buildUserFilter(java.lang.String exsitingFilter)
Returns a that contains the existing filter plus a filter by user ID if that the resource is user-specific and the user is a non-ADMIN user, or just the existing filter for all other cases.

Parameters:
exsitingFilter - The existing filter on which to add a filter by user ID for non-ADMIN users of user-specific resources.
Returns:
If the user is non-ADMIN and it's a user specific resource, the existing filter plus an additional filter by user ID; otherwise, the existing filter.

getUserIDForFilter

protected java.lang.String getUserIDForFilter()
Gets the user id used in the filter for retrieving the data related to the current signed on user.

Returns:
user id string

getCompanyIDForFilter

protected java.lang.String getCompanyIDForFilter()
Gets the company id used in the filter for retrieving the data related to the current company.

Returns:
company id string

getPreparedStatement

protected java.sql.PreparedStatement getPreparedStatement(java.sql.Connection connection,
                                                          java.lang.String topRowCount,
                                                          java.lang.String columnNames,
                                                          java.lang.String filter,
                                                          java.lang.String orderBy,
                                                          BindVariables bindVariables,
                                                          int resultSetType,
                                                          int resultSetConcurrency)
                                                   throws java.sql.SQLException
Get a PreparedStatement for the SELECT query with the given criteria and set the filter bind variables of the value

Parameters:
connection - The JDBC connection which provides a JDBC connectivity
topRowCount - the number of rows to be returned from the underlying DB
columnNames - the column names to be included in the SQL statement
filter - the selection criteria of the SQL statement
orderBy - the order by clause string
bindVariables - the variables to be bound for the filter expression
resultSetType - the type of the result set which determines the navigable capability, sensitivity of changes of the result set returned by preparedStament's executeQuery method
resultSetConcurrency - the result set's concurrency whether it is read only,updateable,etc
Returns:
An PreparedStatement which has bind variables and their value set
Throws:
java.sql.SQLException - SQLException

getQueryStringForParam

protected java.lang.String getQueryStringForParam(java.sql.Connection connection,
                                                  java.lang.String tableName,
                                                  java.lang.String topRowCount,
                                                  java.lang.String columnNames,
                                                  java.lang.String filter,
                                                  java.lang.String orderBy)
                                           throws java.sql.SQLException
Get a query string that can be supplied to an RDBMS SQL query processing engine

Parameters:
connection - The JDBC connection which provides a JDBC connectivity
tableName - the JDBC table name
topRowCount - the maximum number of records to be returned for the criteria
columnNames - the table column to be included in the SQL statement
filter - the criteria(WHERE clause string of SQL statement)
orderBy - the order by clause
Returns:
An SQL statement string
Throws:
java.sql.SQLException - SQLException

getColumnNamesFromList

protected java.lang.String getColumnNamesFromList(java.util.ArrayList<java.lang.String> columnList)
This method takes an array of column names and appends them in to one string with commas separating the names.

Parameters:
columnList - The list of columns that is to be projected
Returns:
a string of all the column names appended together separated by commas.

getOrderByClause

protected java.lang.String getOrderByClause(java.util.List<OrderByParameter> orderByParameters)
Gets a string of the form "SEG1 desc,SEG2,SEG3 desc" for the given orderByParameters

Parameters:
orderByParameters - list of order by parameters
Returns:
An SQL order by clause

getOrderByClauseForKeyField

protected java.lang.String getOrderByClauseForKeyField(boolean ascending)
Gets a string of the form "SEG1 desc,SEG2,SEG3 desc" for the primary key(composite key)

Parameters:
ascending - the direction of order by columns
Returns:
SQL order by clause

splitKeyIntoSegments

protected static java.lang.String[] splitKeyIntoSegments(java.lang.String key,
                                                         java.lang.String delimiter)
Split the key into array for the given delimiter

Parameters:
key - key string
delimiter - delimiting string
Returns:
the array of strings for the key

splitResourceSelectorKeyIntoSegments

public static java.lang.String[] splitResourceSelectorKeyIntoSegments(java.lang.String key)
Form a string array say {'1','1','3'} from the input URL say (...(1;1;3))

Parameters:
key - the input key string in the URL
Returns:
the array of strings for the key URL

moveRecordPointerToKeyInURL

protected boolean moveRecordPointerToKeyInURL(java.lang.String keyInURL,
                                              java.sql.ResultSet resultSet)
                                       throws java.sql.SQLException
Parameters:
keyInURL - keyInURL string
resultSet - ResultSet
Returns:
boolean true if success, false otherwise
Throws:
java.sql.SQLException - SQLException

getKeyValueForKeyName

protected java.lang.String getKeyValueForKeyName(java.sql.ResultSet resultSet)
                                          throws java.sql.SQLException
Gets the key field value for the primary key(composite keys) from the result set

Parameters:
resultSet - the result set from which the keys value are extracted
Returns:
the key values string delimited by the specified segment separator
Throws:
java.sql.SQLException - SQLException

getCaseInsensitiveColumns

protected java.util.Map<java.lang.String,java.lang.String> getCaseInsensitiveColumns()
Gets the map that contains column names in lower case as key and column names in correct case as value

Returns:
The map that contains column names in lower case as key and column names in correct case as value

getDefaultFeedCount

protected int getDefaultFeedCount()
Gets the default number of entries to be returned by the resource kind.

Returns:
the default feed size

getMaxFeedCount

protected int getMaxFeedCount()
Gets the maximum number of entries to be returned by the resource kind.

Returns:
the maximum feed size

getDatabaseType

protected JDBCDatabaseType getDatabaseType()
Gets the type of database that the resource kind's current connection is using.

Returns:
The type of database that the resource kind's current connection is using.

getConnection

protected java.sql.Connection getConnection()

Gets a JDBC connection from the underlying connection pool associated with the resource kind.

NOTE: The caller (most likely a subclass) is responsible for freeing the connection by calling freeConnection.

Returns:
A JDBC Connection object which is got from available connection pool, and which the caller is responsible for freeing.

freeConnection

protected void freeConnection(java.sql.Connection connection)
Free the connection in connection pool.

Parameters:
connection - Current JDBC connection

getAuthToken

protected java.lang.String getAuthToken()
Gets the JDBCResource kinds authentication token.

Returns:
authToken authToken string

findUIContentTextValueInDB

protected java.lang.String findUIContentTextValueInDB(java.lang.String textId,
                                                      java.lang.String language)

Looks in the UI content table for (and returns if found) the associated text value based on the specified text ID and language and using the specified opened prepared statement, falling back to the default language if such a value was not found in the original language to search for, and returning "" if no such value was found even after fallback.

NOTE: This method never returns null, though it may return "" (including for the case where the text ID is null or empty).

NOTE: It's very important that any resource kind that calls this method must have already ensured that the UI content table and cache were created and populated (usually by having a call in that resource kind's constructor that calls the UI content resource kind's static "table" creation method)

Parameters:
textId - The ID of the text that we want to search for - if this ID is null or empty, "" will be returned (as a text ID is not required).
language - The lower-cased language to start the search with - if the text ID is not found in that language and it is not the default langage ("eng"), we will fall back and try the search using the default language.
Returns:
The text value from the UI content table that is associated with the specified text ID and language, or if not found, the one for the specified text ID but in the default language, or if still not found, "".

getTransText

protected java.lang.String getTransText(java.lang.String textId)

Returns translated value on the string.

NOTE: It's very important that any resource kind that calls this method must have already ensured that the UI content table and cache were created and populated (usually by having a call in that resource kind's constructor that calls the UI content resource kind's static "table" creation method)

Parameters:
textId - transText string with all (but language)information for retrieving the translated value from UIContent
Returns:
a translated string

supportGet

protected abstract boolean supportGet()
Indicates whether the ResourceKind in general supports GET or not.

Returns:
True if the ResourceKind supports GET, false otherwise.

supportPut

protected abstract boolean supportPut()
Indicates whether the ResourceKind in general supports PUT or not.

Returns:
True if the ResourceKind supports PUT, false otherwise.

supportPost

protected abstract boolean supportPost()
Indicates whether the ResourceKind in general supports POST or not.

Returns:
True if the ResourceKind supports POST, false otherwise.

supportDelete

protected abstract boolean supportDelete()
Indicates whether the ResourceKind in general supports DELETE or not.

Returns:
True if the ResourceKind supports DELETE, false otherwise.

canGet

public boolean canGet(UserInfo user,
                      java.sql.Connection connection)
Indicates whether the user has the privilege to do GET against the ResourceKind.

Parameters:
user - The signed on user.
connection - The database connection.
Returns:
True if the user has the privilege to do GET against the ResourceKind.

canPut

public boolean canPut(UserInfo user,
                      java.sql.Connection connection)
Indicates whether the user has the privilege to do PUT against the ResourceKind.

Parameters:
user - The signed on user.
connection - The database connection.
Returns:
True if the user has the privilege to do PUT against the ResourceKind.

canPost

public boolean canPost(UserInfo user,
                       java.sql.Connection connection)
Indicates whether the user has the privilege to do POST against the ResourceKind.

Parameters:
user - The signed on user.
connection - The database connection.
Returns:
True if the user has the privilege to do POST against the ResourceKind.

canDelete

public boolean canDelete(UserInfo user,
                         java.sql.Connection connection)
Indicates whether the user has the privilege to do DELETE against the ResourceKind.

Parameters:
user - The signed on user.
connection - The database connection.
Returns:
True if the user has the privilege to do DELETE against the ResourceKind.

canGetOnData

protected boolean canGetOnData(SDataRequest request,
                               java.sql.Connection connection)
                        throws java.sql.SQLException
Indicates whether the user has the privilege to GET the data specified in the request.

Parameters:
request - The GET request.
connection - The database connection.
Returns:
True is the user has the privilege to GET the data specified in the request.
Throws:
java.sql.SQLException - SQLException

canPutOnData

protected boolean canPutOnData(SDataRequest request,
                               java.sql.Connection connection)
                        throws java.sql.SQLException
Indicates whether the user has the privilege to PUT the data specified in the request.

Parameters:
request - The PUT request.
connection - The database connection.
Returns:
True is the user has the privilege to PUT the data specified in the request.
Throws:
java.sql.SQLException - SQLException

canPostOnData

protected boolean canPostOnData(SDataRequest request,
                                java.sql.Connection connection)
                         throws java.sql.SQLException
Indicates whether the user has the privilege to POST the data specified in the request.

Parameters:
request - The POST request.
connection - The database connection.
Returns:
True is the user has the privilege to POST the data specified in the request.
Throws:
java.sql.SQLException - SQLException

canDeleteOnData

protected boolean canDeleteOnData(SDataRequest request,
                                  java.sql.Connection connection)
                           throws java.sql.SQLException
Indicates whether the user has the privilege to DELETE the data specified in the request.

Parameters:
request - The DELETE request.
connection - The database connection.
Returns:
True is the user has the privilege to DELETE the data specified in the request.
Throws:
java.sql.SQLException - SQLException

getUserIDField

protected java.lang.String getUserIDField()
Gets the user id field name in the table/xml.

Returns:
The user id field name

getCompanyIDField

protected java.lang.String getCompanyIDField()
Gets the company id field name in the table/xml.

Returns:
The company id field name

isUserSpecificResource

public abstract boolean isUserSpecificResource()
Indicates whether the resource is user specific or not. If the resource is user specific, it generally requires user sign on.

Returns:
True if the resource is user specific, false otherwise.

requiresSignon

protected boolean requiresSignon()
Indicates whether the user needs to sign on in order to access the resource kind.

Returns:
True if the user needs to sign on in order to access the resource kind, false otherwise.

getCurrentUser

public UserInfo getCurrentUser()
Gets the current signed on user. The method will return null if the resource kind doesn't require sign on.

Returns:
The current signed on user.

requiresUserIdInjection

public boolean requiresUserIdInjection()
Override and return true if the userId is required and is provided by server not clients. E.G. PreferenceStores

Returns:
true if the userId is required

requiresCompanyIdInjection

public boolean requiresCompanyIdInjection()
Override and return true if the companyId is required and is provided by server not clients. E.G. PreferenceStores

Returns:
true if the companyId is required

getCurrentRequest

protected SDataRequest getCurrentRequest()
Gets the current request.

Returns:
The current request.

getApplicationContext

protected ApplicationContext getApplicationContext()
Gets the ApplicationContext.

Returns:
The ApplicationContext .

maintainTable

protected void maintainTable(ApplicationContext context,
                             java.sql.Connection connection,
                             java.lang.String xmlFileName,
                             java.util.List<FieldDefinition> allTableFields,
                             java.lang.String defaultKeys,
                             java.lang.String defaultCompanyID)
maintain the database table used by this resource kind.

Parameters:
context - the application context in which we are working
connection - a connection we can use
xmlFileName - the (partial) name of the xml file that contains initialization data.
allTableFields - all the table fields
defaultKeys - the default keys
defaultCompanyID - the default company ID to use if upgrading, or null if the table should not have a company ID added during upgrade

addCompanyIDField

protected void addCompanyIDField(java.lang.String defaultCompanyID,
                                 java.sql.Connection connection)
Takes the set of records of the default company and creates a new sets for each company registered in Accpac

Parameters:
defaultCompanyID - name of the default company
connection - a connection we can use

addRecordsForAllCompanies

protected void addRecordsForAllCompanies(java.lang.String defaultCompanyID,
                                         java.sql.Connection connection)
Takes the set of records of the default company and creates a new sets for each company registered in Accpac

Parameters:
defaultCompanyID - name of the default company
connection - a connection we can use


Copyright © 2011 Sage Software, Inc. All rights reserved.