public class DataSourceImpl extends java.lang.Object implements DataSource
The DataSource is a programming interface to Web Central data access layer. Web Central data access layer implements declarative object-relational mapping, secure data access, and transparent data localization using metadata defined in the ARCHIBUS data dictionary.
When the DataSource is used to read or write data, it transparently performs ARCHIBUS-specific processing:
Applies ARCHIBUS security: checks whether the current user has read/write permissions for fields;
Applies current user VPA restrictions (if they are applicable to the query table/fields);
For tables with localized fields, chooses field according to the current user locale;
Converts data values from database-specific formats to Java objects and back;
Generates SQL queries using database-specific SQL dialect.
Handles transactions and exceptions, maps database-specific exceptions to ARCHIBUS user-friendly exceptions.
Optionally formats data values for the current user locale.
Modifier and Type | Class and Description |
---|---|
static class |
DataSourceImpl.Parameter
Defines an SQL query parameter.
|
static class |
DataSourceImpl.SortField
Represents a sort field.
|
static class |
DataSourceImpl.TableAndRole
Represents database table and its role in the data source.
|
DataSource.RecordHandler
Modifier and Type | Field and Description |
---|---|
protected boolean |
applyVpaRestrictions
The applyVpaRestrictions property enables or disables VPA restrictions for all read queries,
whether the Data Source uses custom SQL or not.
|
protected org.apache.log4j.Category |
basicRulesLog
Optional logger that is passed in the EventHandlerContext when basic rules are executed.
|
protected java.util.List<com.archibus.datasource.VirtualFieldDef> |
calculatedFieldDefs
List of calculated field definitions.
|
static java.lang.String |
CASCADE_HANDLER
Spring bean name.
|
protected com.archibus.datasource.CascadeHandler |
cascadeHandler
Optional: cascading update/delete handler.
|
protected com.archibus.datasource.SqlExpressions |
customSqlQueries
Map contains custom SQL queries for database dialects.
|
protected com.archibus.config.Database.Immutable |
database
Database instance
|
protected java.lang.String |
databaseRole
Database role.
|
protected com.archibus.model.view.datasource.AbstractDataSourceDef |
dataSourceDef
If the data source has been loaded from the view file, this property refers to the data
source definition.
|
protected boolean |
doNotWrapCustomSql
If true, custom SQL queries are not wrapped inside SELECT * FROM (customQuery) AS tableName
|
protected EventHandlerContext |
eventHandlerContext
EventHandlerContext, not null if the DataSource is used by a workflow rule.
|
protected com.archibus.utility.expr.ExpressionContext |
expressionContext
Context for evaluating expressions.
|
protected java.util.List<java.lang.String> |
fieldNames
Full names of all fields, for main and standard tables.
|
protected java.util.List<java.lang.String> |
fieldNamesForNewRecord
List of field names that have default values for new record.
|
protected boolean |
hasMoreRecords
Whether preceding call to retrieveRecords() did not read all records due to record limit.
|
protected boolean |
isAutoCommit
If autoCommit is set, the DataSource commits changes after each data access call.
|
protected boolean |
isDistinct
True if generated SQL query should include SELECT DISTINCT.
|
protected java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> |
keyFieldsByFullName
Map that contains PK and FK fields keyed by their full names.
|
protected java.util.Locale |
locale
Current user locale
|
protected org.apache.log4j.Category |
log
Logger for this class and subclasses.
|
protected com.archibus.schema.TableDef.ThreadSafe |
mainTableDef
Main table definition.
|
protected java.lang.String |
mainTableName
Name of the main table
|
protected int |
maxRecords
How many records can be retrieved via retrieveRecords().
|
protected java.util.Map<java.lang.String,DataSourceImpl.Parameter> |
parameters
Map of named parameter definitions.
|
protected boolean |
parametersChanged
This flag is set to true by the setParameter() method to indicate that SQL restrictions and
SQL queries have to be re-evaluated before next data access call.
|
protected com.archibus.config.ContextCacheable.Immutable |
parentContext
Web Central context.
|
protected java.util.List<com.archibus.db.RestrictionBaseImpl> |
persistentRestrictions
AXVW and VPA restrictions.
|
protected java.util.ArrayList<com.archibus.db.ViewField.Immutable> |
primaryKeyFields
List of primary key field definitions.
|
protected com.archibus.config.Project.Immutable |
project
Project instance
|
protected com.archibus.datasource.DataSourceQueryImpl |
query
SQL query implementation for the main table.
|
protected java.util.List<com.archibus.datasource.restriction.Restrictions.Restriction> |
restrictions
List
|
protected java.util.Map<java.lang.String,java.lang.Object> |
restrictionValues
Map contains names and values of fields from the applied client-side restriction.
|
static java.lang.String |
SCRIPT_INJECTION_HANDLER
Spring bean name.
|
protected com.archibus.datasource.SqlInjectionHandler |
scriptInjectionHandler
Optional: Script injection handler.
|
protected java.util.List<DataSourceImpl.SortField> |
sortFields
List of sort order fields.
|
static java.lang.String |
SQL_INJECTION_HANDLER
Spring bean name.
|
protected com.archibus.datasource.SqlInjectionHandler |
sqlInjectionHandler
Optional: SQL injection handler.
|
protected java.util.List<com.archibus.datasource.DataSourceQueryImpl> |
standardQueries
SQL query implementations for standard tables.
|
protected java.util.List<DataSourceImpl.TableAndRole> |
tablesAndRoles
List
|
protected boolean |
useHierarchicalSecurityRestriction
True if generated SQL query should include per-user hierarchical security restriction.
|
protected java.util.List<com.archibus.datasource.VirtualFieldDef> |
virtualFieldDefs
List of virtual field definitions.
|
protected java.util.List<com.archibus.db.ViewField.Immutable> |
virtualFields
List of virtual fields.
|
protected java.util.ArrayList<com.archibus.db.ViewField.Immutable> |
visibleFields
List of visible field definitions.
|
protected java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> |
visibleFieldsByName
Map that contains visible fields keyed by their full names.
|
DATA_TYPE_BOOLEAN, DATA_TYPE_CURRENCY, DATA_TYPE_DATE, DATA_TYPE_DOUBLE, DATA_TYPE_INTEGER, DATA_TYPE_MEMO, DATA_TYPE_NUMBER, DATA_TYPE_TEXT, DATA_TYPE_TIME, DATA_TYPE_VERBATIM, DB_ROLE_DATA, DB_ROLE_SCHEMA, DB_ROLE_SECURITY, ROLE_MAIN, ROLE_STANDARD, SORT_ASC, SORT_DESC
Constructor and Description |
---|
DataSourceImpl()
Constructor.
|
DataSourceImpl(DataSourceImpl anotherDataSource)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
DataSource |
addCalculatedField(com.archibus.datasource.VirtualFieldDef calculatedField)
Adds a calculated field to the data source.
|
DataSource |
addField(java.lang.String name)
Adds specified main table field to the data source query.
|
DataSource |
addField(java.lang.String[] names)
Adds specified main table fields to the data source query.
|
DataSource |
addField(java.lang.String table,
java.lang.String name)
Adds specified field to the data source query.
|
DataSource |
addField(java.lang.String table,
java.lang.String[] names)
Adds specified fields to the data source query.
|
DataSource |
addParameter(java.lang.String name,
double value,
java.lang.String dataType) |
DataSource |
addParameter(java.lang.String name,
int value,
java.lang.String dataType) |
DataSource |
addParameter(java.lang.String name,
java.lang.Object value,
java.lang.String dataType) |
DataSource |
addParameter(java.lang.String name,
java.lang.String value,
java.lang.String dataType)
Adds a query parameter.
|
void |
addPersistentRestrictions(java.util.List restrictionElements)
Adds view and/or VPA restrictions to the data source.
|
DataSource |
addQuery(java.lang.String sql)
Adds a generic dialect SQL query to the data source.
|
DataSource |
addQuery(java.lang.String sql,
java.lang.String dialect)
Adds an SQL query to the data source.
|
DataSource |
addRestriction(com.archibus.datasource.restriction.Restrictions.Restriction.Clause c)
Adds a restriction clause.
|
DataSource |
addRestriction(com.archibus.datasource.restriction.Restrictions.Restriction r)
Adds a restriction.
|
void |
addRestrictionsToQuery()
Adds all (view and VPA) restrictions to the query def.
|
DataSource |
addSort(java.lang.String name)
Adds a main table sort field to the data source query, in SORT_ASC mode.
|
DataSource |
addSort(java.lang.String table,
java.lang.String name)
Adds a sort field to the data source query, in SORT_ASC mode.
|
DataSource |
addSort(java.lang.String table,
java.lang.String name,
java.lang.String order)
Adds a sort field to the data source query.
|
DataSource |
addTable(java.lang.String name)
Adds specified table to the data source query, as a "main" table.
|
DataSource |
addTable(java.lang.String name,
java.lang.String role)
Adds specified table in specified role to the data source query.
|
DataSource |
addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType)
Adds a virtual field to the data source.
|
DataSource |
addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType,
int size,
int decimals)
Adds a virtual field to the data source.
|
DataSource |
addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType,
int size,
int decimals,
java.lang.String title) |
protected void |
checkAutoCommit()
If autoCommit is set, commit pending database changes.
|
void |
checkSetContext()
If the parent Context has not been set, finds and sets it.
|
DataSource |
clearRestrictions()
Clears all restrictions defined in AXVW.
|
void |
commit()
Commit current database transaction.
|
protected void |
copyProperties(DataSourceImpl copy)
Copies configuration properties into another DataSource.
|
DataSource |
createCopy()
Creates a copy of this data source.
|
com.archibus.datasource.data.DataRecord |
createNewRecord()
Creates new DataRecord with default values for all fields defined in the data source.
|
org.json.JSONArray |
createPrimaryKeyIds()
Creates primary key column definitions in JSON format from the data source.
|
com.archibus.datasource.data.DataRecord |
createRecord()
Creates new DataRecord with default values for all fields defined in the data source.
|
com.archibus.datasource.data.DataRecord |
createRecordFromContext()
Creates new DataRecord with default values for all fields defined in the data source.
|
java.lang.String |
createSqlForLastAddedPK(java.util.Map fieldValues)
Generates SQL query that can be used to retrieve the primary key of the last saved record.
|
com.archibus.db.ViewField.Immutable |
createVirtualField(java.lang.String fieldName,
boolean localized)
Creates virtual field definition.
|
com.archibus.db.ViewField.Immutable |
createVirtualViewField(java.lang.String table,
java.lang.String name,
java.lang.String fieldJavaType,
java.text.NumberFormat format)
Creates and returns virtual view field for specified Java field type.
|
void |
deleteRecord(com.archibus.datasource.data.DataRecord record)
Deletes existing record.
|
void |
deleteRecord(java.util.Map fieldValues)
Deletes record specified by field values.
|
void |
enableIdLookup(boolean value)
Sets the idLookupEnabled property.
|
java.lang.String |
evaluateExpressions(java.lang.String value,
boolean literalizeUserName)
Evaluates #{...} expressions and returns resolved string.
|
protected void |
evaluateSqlExpressions()
Evaluates expressions in custom SQL queries, calculated fields, and restrictions.
|
void |
executeUpdate()
Executes SQL update query, set using addQuery().
|
void |
executeUpdateRequired()
Executes SQL update query, set using addQuery().
|
com.archibus.db.ViewField.Immutable |
findField(java.lang.String fullName)
Returns a field definition for specified full field name.
|
com.archibus.db.ViewField.Immutable |
findKeyField(java.lang.String fullName)
Returns a field definition for specified full field name.
|
DataSourceImpl.TableAndRole |
findTable(java.lang.String tableName)
Returns the table and role for specific table, or null if the table is not defined in the
data source.
|
com.archibus.db.ViewField.Immutable |
findVirtualField(java.lang.String fullName)
Loop through the virtual fields for the current data source and Returns a field definition
for specified full field name.
|
java.lang.String |
formatJoin(java.lang.String fieldName)
Generates a join between the table of specified field and its validating table, if any.
|
java.lang.String |
formatSqlForPersistentRestrictions()
Generates SQL WHERE clause from VPAs for current user/role applicable to the main table in
current DataSource.
|
java.lang.String |
formatSqlForPersistentRestrictionsForTable(java.lang.String tableName)
Generates SQL WHERE clause from VPAs for current user/role applicable to the specified table
in current DataSource.
|
java.lang.String |
formatSqlForPersistentRestrictionsForTableAndRole(java.lang.String tableName,
java.lang.String roleName)
Generates SQL WHERE clause from VPAs applicable to the specified table in current DataSource.
|
java.lang.String |
formatSqlForRestriction(java.lang.String id)
Generates SQL WHERE clause from a named restriction.
|
java.lang.String |
formatSqlQuery(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions,
java.util.List sortValues,
java.util.List filterValues,
boolean isOrderbyAllowed,
boolean doNotWrap)
Formats and returns an SQL query based on:
view tables and fields;
view restrictions;
view SQL queries;
current user VPA restriction;
additional restrictions.
|
java.lang.String |
formatSqlQuery(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions,
java.util.List sortValues,
java.util.List filterValues,
boolean isOrderbyAllowed,
boolean doNotWrap,
java.lang.String fieldName)
Formats and returns an SQL query.
|
java.lang.String |
formatSqlQuery(java.lang.String restrictionString,
boolean doNotWrap)
Formats and returns an SQL query based on: previously added tables, fields, sort fields,
restrictions, and custom SQL queries; current user VPA restriction; client-side restriction.
|
java.lang.String |
formatSqlQuery(java.lang.String restrictionString,
java.util.List sortValues,
java.util.List filterValues,
boolean isOrderbyAllowed,
boolean doNotWrap)
Formats and returns an SQL query based on: previously added tables, fields, sort fields,
restrictions, and custom SQL queries; current user VPA restriction; client-side restriction.
|
java.lang.String |
formatSqlQueryForField(java.lang.String restrictionString,
java.util.List sortValues,
java.util.List filterValues,
boolean isOrderbyAllowed,
boolean doNotWrap,
java.lang.String fieldName)
Formats and returns an SQL query that selects a single specified field.
|
java.util.List<com.archibus.db.ViewField.Immutable> |
getAllFields()
Returns a list of field definitions for visible and/or virtual fields.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getAllRecords()
Retrieves records that contains values for all fields defined in the data source, using no
record limit.
|
com.archibus.datasource.VirtualFieldDef |
getCalculatedFieldDef(java.lang.String table,
java.lang.String name)
Returns specified virtual field definition.
|
com.archibus.config.ContextCacheable.Immutable |
getContext()
Returns parent context.
|
java.lang.String |
getDatabaseRole()
Returns database role.
|
com.archibus.model.view.datasource.AbstractDataSourceDef |
getDataSourceDef() |
java.util.List<EventHandlerBase.DbField> |
getDbFieldsForNewRecord()
Returns a list of DB field definitions for default new record.
|
java.util.List<EventHandlerBase.DbField> |
getDbFieldsForPrimaryKeys()
Returns the list of fields for primary keys of the main table.
|
java.util.Map<java.lang.String,EventHandlerBase.DbField> |
getDbFieldsForPrimaryKeysAsMap()
Returns a map of DB field definitions for key fields.
|
java.util.List<EventHandlerBase.DbField> |
getDbFieldsForVisibleFields()
Returns a list of DB field definitions for all fields defined in the data source.
|
com.archibus.datasource.data.DataRecord |
getDefaultRecord(java.lang.String restriction)
Returns DataRecord with default values for all fields defined in the data source.
|
java.util.List<java.lang.String> |
getFieldNames() |
java.lang.String |
getId() |
com.archibus.schema.TableDef.ThreadSafe |
getMainTableDef()
Returns main table definition.
|
java.lang.String |
getMainTableName()
Returns main table name.
|
java.util.Map<java.lang.String,DataSourceImpl.Parameter> |
getParameters()
Returns all parameters.
|
static java.util.List<java.lang.String> |
getPKeyFieldNamesForTable(java.lang.String tableName,
com.archibus.config.Project.Immutable project)
Returns a canonical list of primary key field names for a specified table.
|
java.util.List<java.lang.String> |
getPrimaryKeyFieldNamesForTable(java.lang.String tableName)
Returns a collection of the main table's primary key field names.
|
java.util.List<com.archibus.db.ViewField.Immutable> |
getPrimaryKeyFields()
Returns a list of primary key fields.
|
com.archibus.datasource.SqlExpressions |
getQueries()
Returns all custom queries.
|
protected com.archibus.datasource.DataSourceQueryImpl |
getQueryInstance(com.archibus.config.Database.Immutable database)
Returns new query instance.
|
com.archibus.datasource.data.DataRecord |
getRecord()
Retrieves a single record that contains values for all fields defined in the data source.
|
com.archibus.datasource.data.DataRecord |
getRecord(java.lang.String restriction)
Retrieves a single record that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords()
Retrieves records that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords(com.archibus.model.view.datasource.AbstractRestrictionDef restrictionDef)
Retrieves records that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions)
Retrieves records that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions,
int maxRecords)
Retrieves records that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords(java.lang.String restriction)
Retrieves records that contains values for all fields defined in the data source.
|
java.util.List<com.archibus.datasource.data.DataRecord> |
getRecords(java.lang.String restriction,
int maxRecords)
Retrieves records that contains values for all fields defined in the data source.
|
com.archibus.model.view.datasource.ClauseDef.RelativeOperation |
getRestrictionRelativeOperation()
Returns relative operation used to combine multiple client restrictions.
|
java.util.List<com.archibus.datasource.restriction.Restrictions.Restriction> |
getRestrictions()
Returns a list of restriction definitions.
|
java.util.Map<java.lang.String,java.lang.Object> |
getRestrictionValues()
Returns restrictions values passed in from the client.
|
java.util.List<DataSourceImpl.SortField> |
getSortFields()
Returns a list of sort field definitions.
|
java.util.List<DataSourceImpl.TableAndRole> |
getTablesAndRoles()
Returns a list of table names and roles.
|
java.lang.String |
getTitle() |
java.lang.String |
getViewName() |
com.archibus.datasource.VirtualFieldDef |
getVirtualFieldDef(java.lang.String table,
java.lang.String name)
Returns specified virtual field definition.
|
java.util.List<com.archibus.db.ViewField.Immutable> |
getVirtualFields()
Returns a list of virtual fields.
|
java.util.List<com.archibus.db.ViewField.Immutable> |
getVisibleFields()
Returns a list of visible fields.
|
java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> |
getVisibleFieldsByName()
Returns a map of visible fields.
|
boolean |
hasCustomQuery()
Returns true if the data source uses custom SQL qeury.
|
boolean |
hasMoreRecords()
Returns true if preceding call to retrieveRecords() did not read all records due to record
limit.
|
boolean |
hasVirtualFields()
Returns true if the data source defines virtual fields for custom SQL qeury.
|
boolean |
isDistinct()
Gets the distinct attribute
|
boolean |
isIdLookupEnabled()
Whether this data source can use lookup fields.
|
boolean |
isOracle()
Returns true if the current database server is Oracle.
|
boolean |
isSqlServer()
Returns true if the current database server is SQL Server.
|
boolean |
isSybase()
Returns true if the current database server is Sybase.
|
java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> |
parseClientRestrictions(java.lang.String restrictionString)
Creates parsed or SQL restriction from the string input parameter.
|
void |
queryRecords(DataSource.RecordHandler recordHandler)
Executes SQL query and calls specified callback for each retrieved record.
|
void |
queryRecords(java.lang.String restriction,
DataSource.RecordHandler recordHandler)
Executes SQL query and calls specified callback for each retrieved record.
|
void |
rollback()
Rollback current database transaction.
|
com.archibus.datasource.data.DataRecord |
saveRecord(com.archibus.datasource.data.DataRecord record)
Saves new or updates existing record.
|
DataSource |
setApplyVpaRestrictions(boolean applyVpaRestrictions)
The applyVpaRestrictions property enables or disables VPA restrictions for all read queries,
whether the Data Source uses custom SQL or not.
|
DataSource |
setAutoCommit(boolean autoCommit)
Sets the autoCommit flag.
|
DataSource |
setContext()
Sets data source context and initializes context-dependent data source state based on the
current thread context.
|
DataSource |
setContext(com.archibus.config.ContextCacheable.Immutable context)
Sets data source context and initializes context-dependent data source state.
|
DataSource |
setContext(EventHandlerContext eventHandlerContext)
Sets data source context and initializes context-dependent data source state.
|
DataSource |
setDatabaseRole(java.lang.String role)
Set database role for this DataSource to access.
|
void |
setDataSourceDef(com.archibus.model.view.datasource.AbstractDataSourceDef dataSourceDef) |
DataSource |
setDistinct(boolean isDistinct)
Sets isDistinct flag.
|
DataSource |
setDoNotWrapCustomSql(boolean value)
Sets the doNotWrapCustomSql property.
|
void |
setId(java.lang.String id) |
DataSource |
setMaxRecords(int maxRecords)
Sets the max number of records that can be retrieved by consequent calls to
retrieveRecords().
|
DataSource |
setParameter(java.lang.String name,
java.lang.Object value)
Sets new value for specified parameter.
|
void |
setRestrictionRelativeOperation(com.archibus.model.view.datasource.ClauseDef.RelativeOperation restrictionRelativeOperation)
Sets relative operation used to combine multiple client restrictions.
|
void |
setTitle(java.lang.String title) |
DataSource |
setUseHierarchicalSecurityRestriction(boolean useHierarchicalSecurityRestriction)
Sets the useHierarchicalSecurityRestriction property.
|
void |
setViewName(java.lang.String viewName) |
void |
updateRecord(com.archibus.datasource.data.DataRecord record)
Updates existing record specified by the primary key values.
|
protected boolean |
useCascadeHandler() |
boolean |
useVirtualFields()
Returns true if virtual fields must be used instead of visible fields to handle JDBC
resultset.
|
public static final java.lang.String CASCADE_HANDLER
public static final java.lang.String SQL_INJECTION_HANDLER
public static final java.lang.String SCRIPT_INJECTION_HANDLER
protected java.lang.String databaseRole
protected java.lang.String mainTableName
protected final java.util.List<DataSourceImpl.TableAndRole> tablesAndRoles
protected final java.util.List<java.lang.String> fieldNames
protected final java.util.List<DataSourceImpl.SortField> sortFields
protected final java.util.List<com.archibus.datasource.VirtualFieldDef> virtualFieldDefs
protected final java.util.List<com.archibus.datasource.VirtualFieldDef> calculatedFieldDefs
protected com.archibus.datasource.SqlExpressions customSqlQueries
protected boolean isDistinct
protected boolean useHierarchicalSecurityRestriction
protected boolean isAutoCommit
protected final java.util.Map<java.lang.String,DataSourceImpl.Parameter> parameters
protected final java.util.List<com.archibus.datasource.restriction.Restrictions.Restriction> restrictions
protected int maxRecords
protected boolean doNotWrapCustomSql
protected boolean applyVpaRestrictions
protected com.archibus.model.view.datasource.AbstractDataSourceDef dataSourceDef
protected boolean hasMoreRecords
protected com.archibus.schema.TableDef.ThreadSafe mainTableDef
protected java.util.ArrayList<com.archibus.db.ViewField.Immutable> visibleFields
protected final java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> visibleFieldsByName
protected final java.util.List<com.archibus.db.ViewField.Immutable> virtualFields
protected java.util.ArrayList<com.archibus.db.ViewField.Immutable> primaryKeyFields
protected final java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> keyFieldsByFullName
protected java.util.Map<java.lang.String,java.lang.Object> restrictionValues
protected com.archibus.datasource.DataSourceQueryImpl query
protected java.util.List<com.archibus.datasource.DataSourceQueryImpl> standardQueries
protected com.archibus.config.ContextCacheable.Immutable parentContext
protected EventHandlerContext eventHandlerContext
protected com.archibus.utility.expr.ExpressionContext expressionContext
protected com.archibus.config.Project.Immutable project
protected com.archibus.config.Database.Immutable database
protected java.util.Locale locale
protected final java.util.List<com.archibus.db.RestrictionBaseImpl> persistentRestrictions
protected java.util.List<java.lang.String> fieldNamesForNewRecord
protected boolean parametersChanged
protected org.apache.log4j.Category log
protected org.apache.log4j.Category basicRulesLog
protected com.archibus.datasource.CascadeHandler cascadeHandler
protected com.archibus.datasource.SqlInjectionHandler sqlInjectionHandler
protected com.archibus.datasource.SqlInjectionHandler scriptInjectionHandler
public DataSourceImpl()
public DataSourceImpl(DataSourceImpl anotherDataSource)
anotherDataSource
- The data source to copy.public DataSource createCopy()
public com.archibus.model.view.datasource.AbstractDataSourceDef getDataSourceDef()
getDataSourceDef
in interface DataSource
public void setDataSourceDef(com.archibus.model.view.datasource.AbstractDataSourceDef dataSourceDef)
setDataSourceDef
in interface DataSource
dataSourceDef
- the dataSourceDef to setpublic java.lang.String getTitle()
getTitle
in interface DataSource
public void setTitle(java.lang.String title)
setTitle
in interface DataSource
title
- the title to setpublic java.lang.String getId()
getId
in interface DataSource
public void setId(java.lang.String id)
setId
in interface DataSource
id
- the id to setpublic java.lang.String getViewName()
getViewName
in interface DataSource
public void setViewName(java.lang.String viewName)
setViewName
in interface DataSource
viewName
- the view name to setpublic DataSource setDatabaseRole(java.lang.String role)
DataSource
setDatabaseRole
in interface DataSource
role
- The database role.public DataSource addTable(java.lang.String name)
DataSource
addTable
in interface DataSource
name
- Table name, i.e. "wr".public DataSource addTable(java.lang.String name, java.lang.String role)
DataSource
addTable
in interface DataSource
name
- Table name, i.e. "wr".role
- Table role, i.e. "standard".public DataSource addField(java.lang.String name)
DataSource
addField
in interface DataSource
name
- Field name, i.e. "status".public DataSource addField(java.lang.String[] names)
DataSource
addField
in interface DataSource
names
- Array of field names.public DataSource addField(java.lang.String table, java.lang.String name)
DataSource
addField
in interface DataSource
table
- Table name, i.e. "wr".name
- Field name, i.e. "status".public DataSource addField(java.lang.String table, java.lang.String[] names)
DataSource
addField
in interface DataSource
table
- Table name, i.e. "wr".names
- Array of field names.public java.util.List<java.lang.String> getFieldNames()
getFieldNames
in interface DataSource
public DataSource addSort(java.lang.String name)
DataSource
addSort
in interface DataSource
name
- Field name, i.e. "status".public DataSource addSort(java.lang.String table, java.lang.String name)
DataSource
addSort
in interface DataSource
table
- Table name, i.e. "wr".name
- Field name, i.e. "status".public DataSource addSort(java.lang.String table, java.lang.String name, java.lang.String order)
DataSource
addSort
in interface DataSource
table
- Table name, i.e. "wr".name
- Field name, i.e. "status".order
- Sort order: asc|desc.public DataSource addVirtualField(java.lang.String table, java.lang.String name, java.lang.String dataType)
DataSource
addVirtualField
in interface DataSource
table
- Table name, matching the SQL query table alias.name
- Virtual field name, matching the calculated SQL column name.dataType
- Virtual field type: text|number|date|time|memo|verbatim.public DataSource addVirtualField(java.lang.String table, java.lang.String name, java.lang.String dataType, int size, int decimals)
DataSource
addVirtualField
in interface DataSource
table
- Table name, matching the SQL query table alias.name
- Virtual field name, matching the calculated SQL column name.dataType
- Virtual field type: text|number|date|time|memo|verbatim.size
- For numeric field, the number of integer digits.decimals
- For numeric field, the number of fraction digits.public DataSource addVirtualField(java.lang.String table, java.lang.String name, java.lang.String dataType, int size, int decimals, java.lang.String title)
addVirtualField
in interface DataSource
public DataSource addCalculatedField(com.archibus.datasource.VirtualFieldDef calculatedField)
DataSource
addCalculatedField
in interface DataSource
calculatedField
- The calculated field definition.public DataSource addQuery(java.lang.String sql)
DataSource
addQuery
in interface DataSource
sql
- The SQL.public DataSource addQuery(java.lang.String sql, java.lang.String dialect)
DataSource
addQuery
in interface DataSource
sql
- The SQL.dialect
- SQL dialect: generic|sybase|oracle|sqlserverpublic com.archibus.datasource.SqlExpressions getQueries()
DataSource
getQueries
in interface DataSource
public DataSource addParameter(java.lang.String name, java.lang.String value, java.lang.String dataType)
DataSource
addParameter
in interface DataSource
name
- Parameter name.value
- Parameter value.dataType
- Parameter type, used to parse the value into an object.public DataSource addParameter(java.lang.String name, java.lang.Object value, java.lang.String dataType)
addParameter
in interface DataSource
public DataSource addParameter(java.lang.String name, int value, java.lang.String dataType)
addParameter
in interface DataSource
public DataSource addParameter(java.lang.String name, double value, java.lang.String dataType)
addParameter
in interface DataSource
public java.util.Map<java.lang.String,DataSourceImpl.Parameter> getParameters()
DataSource
getParameters
in interface DataSource
public DataSource addRestriction(com.archibus.datasource.restriction.Restrictions.Restriction r)
DataSource
addRestriction
in interface DataSource
r
- Restriction.public DataSource addRestriction(com.archibus.datasource.restriction.Restrictions.Restriction.Clause c)
DataSource
addRestriction
in interface DataSource
c
- Restriction clause.public DataSource clearRestrictions()
DataSource
clearRestrictions
in interface DataSource
public DataSource setDistinct(boolean isDistinct)
DataSource
setDistinct
in interface DataSource
isDistinct
- The flag value.public boolean isDistinct()
DataSource
isDistinct
in interface DataSource
public DataSource setUseHierarchicalSecurityRestriction(boolean useHierarchicalSecurityRestriction)
DataSource
setUseHierarchicalSecurityRestriction
in interface DataSource
useHierarchicalSecurityRestriction
- The property value.public DataSource setAutoCommit(boolean autoCommit)
DataSource
setAutoCommit
in interface DataSource
autoCommit
- The flag value.public DataSource setDoNotWrapCustomSql(boolean value)
value
- The property value.public DataSource setApplyVpaRestrictions(boolean applyVpaRestrictions)
DataSource
setApplyVpaRestrictions
in interface DataSource
applyVpaRestrictions
- The property value.public DataSource setParameter(java.lang.String name, java.lang.Object value)
DataSource
setParameter
in interface DataSource
name
- Parameter name.value
- Parameter value.public DataSource setContext(com.archibus.config.ContextCacheable.Immutable context)
DataSource
setContext
in interface DataSource
context
- Web Central context object, typically a UserSession.public DataSource setContext(EventHandlerContext eventHandlerContext)
setContext
in interface DataSource
eventHandlerContext
- Web Central WFR event handler context.public DataSource setContext()
setContext
in interface DataSource
public com.archibus.config.ContextCacheable.Immutable getContext()
protected void copyProperties(DataSourceImpl copy)
copy
- The data source to copy properties to.public java.lang.String getDatabaseRole()
public java.util.List<DataSourceImpl.TableAndRole> getTablesAndRoles()
DataSource
getTablesAndRoles
in interface DataSource
public java.util.List<com.archibus.db.ViewField.Immutable> getVisibleFields()
DataSource
getVisibleFields
in interface DataSource
public java.util.List<com.archibus.db.ViewField.Immutable> getVirtualFields()
DataSource
getVirtualFields
in interface DataSource
public java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> getVisibleFieldsByName()
DataSource
getVisibleFieldsByName
in interface DataSource
public java.util.Map<java.lang.String,java.lang.Object> getRestrictionValues()
DataSource
getRestrictionValues
in interface DataSource
public java.util.List<com.archibus.datasource.restriction.Restrictions.Restriction> getRestrictions()
DataSource
getRestrictions
in interface DataSource
public java.util.List<DataSourceImpl.SortField> getSortFields()
DataSource
getSortFields
in interface DataSource
public java.lang.String getMainTableName()
DataSource
getMainTableName
in interface DataSource
public DataSourceImpl.TableAndRole findTable(java.lang.String tableName)
tableName
- The table name.public java.util.List<com.archibus.db.ViewField.Immutable> getPrimaryKeyFields()
DataSource
getPrimaryKeyFields
in interface DataSource
public java.util.List<java.lang.String> getPrimaryKeyFieldNamesForTable(java.lang.String tableName)
DataSource
getPrimaryKeyFieldNamesForTable
in interface DataSource
tableName
- The table name.public static java.util.List<java.lang.String> getPKeyFieldNamesForTable(java.lang.String tableName, com.archibus.config.Project.Immutable project)
tableName
- The table name.project
- The project.public com.archibus.db.ViewField.Immutable findField(java.lang.String fullName)
DataSource
findField
in interface DataSource
fullName
- Full field name, i.e. "wr.status".public com.archibus.db.ViewField.Immutable findVirtualField(java.lang.String fullName)
DataSource
findVirtualField
in interface DataSource
fullName
- Full field name, i.e. "wr.status".public com.archibus.db.ViewField.Immutable findKeyField(java.lang.String fullName)
fullName
- Full field name, i.e. "wr.status".public com.archibus.schema.TableDef.ThreadSafe getMainTableDef()
DataSource
getMainTableDef
in interface DataSource
public boolean hasCustomQuery()
DataSource
hasCustomQuery
in interface DataSource
public boolean hasVirtualFields()
DataSource
hasVirtualFields
in interface DataSource
public boolean isSqlServer()
DataSource
isSqlServer
in interface DataSource
public boolean isOracle()
DataSource
isOracle
in interface DataSource
public boolean isSybase()
DataSource
isSybase
in interface DataSource
public boolean useVirtualFields()
public java.util.List<EventHandlerBase.DbField> getDbFieldsForVisibleFields()
getDbFieldsForVisibleFields
in interface DataSource
public java.util.List<com.archibus.db.ViewField.Immutable> getAllFields()
getAllFields
in interface DataSource
public com.archibus.datasource.VirtualFieldDef getVirtualFieldDef(java.lang.String table, java.lang.String name)
DataSource
getVirtualFieldDef
in interface DataSource
table
- The table name.name
- The field name.public com.archibus.datasource.VirtualFieldDef getCalculatedFieldDef(java.lang.String table, java.lang.String name)
DataSource
getCalculatedFieldDef
in interface DataSource
table
- The table name.name
- The field name.public java.util.List<EventHandlerBase.DbField> getDbFieldsForNewRecord()
DataSource
getDbFieldsForNewRecord
in interface DataSource
public java.util.List<EventHandlerBase.DbField> getDbFieldsForPrimaryKeys()
public java.util.Map<java.lang.String,EventHandlerBase.DbField> getDbFieldsForPrimaryKeysAsMap()
getDbFieldsForPrimaryKeysAsMap
in interface DataSource
public org.json.JSONArray createPrimaryKeyIds()
createPrimaryKeyIds
in interface DataSource
public com.archibus.db.ViewField.Immutable createVirtualViewField(java.lang.String table, java.lang.String name, java.lang.String fieldJavaType, java.text.NumberFormat format)
DataSource
createVirtualViewField
in interface DataSource
table
- Virtual field table name.name
- Virtual field name.fieldJavaType
- Java class name, such as "java.lang.Double" or "java.sql.Date".format
- NumberFormat instance for numeric felds, or null for other fields.public com.archibus.db.ViewField.Immutable createVirtualField(java.lang.String fieldName, boolean localized)
fieldName
- The field name.localized
- Whether field values should be localized.public java.lang.String formatSqlQuery(java.lang.String restrictionString, boolean doNotWrap)
DataSource
formatSqlQuery
in interface DataSource
restrictionString
- String containing client-side restriction in JSON format.doNotWrap
- True if the data source should not wrap the custom SQL query.public java.lang.String formatSqlQuery(java.lang.String restrictionString, java.util.List sortValues, java.util.List filterValues, boolean isOrderbyAllowed, boolean doNotWrap)
DataSource
formatSqlQuery
in interface DataSource
restrictionString
- String containing client-side restriction in JSON format.sortValues
- The list sort values.filterValues
- The list of filter values.isOrderbyAllowed
- True if the data source can apply the ORDER BY clause.doNotWrap
- True if the data source should not wrap the custom SQL query.public java.lang.String formatSqlQueryForField(java.lang.String restrictionString, java.util.List sortValues, java.util.List filterValues, boolean isOrderbyAllowed, boolean doNotWrap, java.lang.String fieldName)
DataSource
formatSqlQueryForField
in interface DataSource
restrictionString
- String containing client-side restriction in JSON format.sortValues
- The list sort values.filterValues
- The list of filter values.isOrderbyAllowed
- True if the data source can apply the ORDER BY clause.doNotWrap
- True if the data source should not wrap the custom SQL query.fieldName
- The field name.public java.lang.String formatSqlQuery(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions, java.util.List sortValues, java.util.List filterValues, boolean isOrderbyAllowed, boolean doNotWrap)
restrictions
- The list of restriction.sortValues
- The list sort values.filterValues
- The list of filter values.isOrderbyAllowed
- True if the data source can apply the ORDER BY clause.doNotWrap
- True if the data source should not wrap the custom SQL query.public java.lang.String formatSqlQuery(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions, java.util.List sortValues, java.util.List filterValues, boolean isOrderbyAllowed, boolean doNotWrap, java.lang.String fieldName)
restrictions
- The list of restriction.sortValues
- The list sort values.filterValues
- The list of filter values.isOrderbyAllowed
- True if the data source can apply the ORDER BY clause.doNotWrap
- True if the data source should not wrap the custom SQL query.fieldName
- The field name.public java.lang.String formatJoin(java.lang.String fieldName)
Example: rm.dp_id ==> (LEFT OUTER JOIN dp ON rm.dp_id = dp.dp_id)
formatJoin
in interface DataSource
fieldName
- The field name.public java.lang.String formatSqlForRestriction(java.lang.String id)
DataSource
formatSqlForRestriction
in interface DataSource
id
- The restriction ID.public java.lang.String formatSqlForPersistentRestrictions()
DataSource
formatSqlForPersistentRestrictions
in interface DataSource
public java.lang.String formatSqlForPersistentRestrictionsForTable(java.lang.String tableName)
DataSource
formatSqlForPersistentRestrictionsForTable
in interface DataSource
tableName
- of main or standard table in the current DataSource for which to generate
SQL.public java.lang.String formatSqlForPersistentRestrictionsForTableAndRole(java.lang.String tableName, java.lang.String roleName)
DataSource
formatSqlForPersistentRestrictionsForTableAndRole
in interface DataSource
tableName
- of main or standard table in the current DataSource for which to generate
SQL.roleName
- of user role. Can be null.protected void evaluateSqlExpressions()
protected com.archibus.datasource.DataSourceQueryImpl getQueryInstance(com.archibus.config.Database.Immutable database)
database
- public com.archibus.model.view.datasource.ClauseDef.RelativeOperation getRestrictionRelativeOperation()
public void setRestrictionRelativeOperation(com.archibus.model.view.datasource.ClauseDef.RelativeOperation restrictionRelativeOperation)
restrictionRelativeOperation
- The operation.public boolean isIdLookupEnabled()
DataSource
isIdLookupEnabled
in interface DataSource
public void enableIdLookup(boolean value)
enableIdLookup
in interface DataSource
value
- The property value.public void addPersistentRestrictions(java.util.List restrictionElements)
restrictionElements
- The list of XML restrictions.public void addRestrictionsToQuery()
public java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> parseClientRestrictions(java.lang.String restrictionString)
parseClientRestrictions
in interface DataSource
restrictionString
- can contain: - single XML record; - single JSON record; - multiple
JSON records; - literal SQL expression;public java.lang.String evaluateExpressions(java.lang.String value, boolean literalizeUserName)
value
- The value to evaluate.literalizeUserName
- The user name that can be used in expressions.public com.archibus.datasource.data.DataRecord getRecord() throws com.archibus.utility.ExceptionBase
DataSource
getRecord
in interface DataSource
com.archibus.utility.ExceptionBase
public com.archibus.datasource.data.DataRecord getRecord(java.lang.String restriction) throws com.archibus.utility.ExceptionBase
DataSource
getRecord
in interface DataSource
restriction
- The client-side restriction.com.archibus.utility.ExceptionBase
public java.util.List<com.archibus.datasource.data.DataRecord> getRecords()
DataSource
getRecords
in interface DataSource
public java.util.List<com.archibus.datasource.data.DataRecord> getRecords(java.lang.String restriction)
DataSource
getRecords
in interface DataSource
restriction
- Client-supplied restriction string, or null.public java.util.List<com.archibus.datasource.data.DataRecord> getRecords(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions)
DataSource
getRecords
in interface DataSource
restrictions
- The list of restrictions defined using the DB package types.public java.util.List<com.archibus.datasource.data.DataRecord> getRecords(java.lang.String restriction, int maxRecords)
DataSource
getRecords
in interface DataSource
restriction
- Client-supplied restriction string, or null.maxRecords
- The record limit, or 0 if there is no record limit.public java.util.List<com.archibus.datasource.data.DataRecord> getRecords(java.util.List<com.archibus.db.RestrictionSqlBase.Immutable> restrictions, int maxRecords)
DataSource
getRecords
in interface DataSource
restrictions
- The list of restrictions defined using the DB package types.maxRecords
- The record limit, or 0 if there is no record limit.public java.util.List<com.archibus.datasource.data.DataRecord> getRecords(com.archibus.model.view.datasource.AbstractRestrictionDef restrictionDef)
DataSource
getRecords
in interface DataSource
restrictionDef
- The restriction definition.public java.util.List<com.archibus.datasource.data.DataRecord> getAllRecords()
DataSource
getAllRecords
in interface DataSource
public void queryRecords(DataSource.RecordHandler recordHandler)
DataSource
queryRecords
in interface DataSource
recordHandler
- The callback.public void queryRecords(java.lang.String restriction, DataSource.RecordHandler recordHandler)
DataSource
queryRecords
in interface DataSource
restriction
- The client-side restriction.recordHandler
- The callback.public com.archibus.datasource.data.DataRecord saveRecord(com.archibus.datasource.data.DataRecord record)
DataSource
saveRecord
in interface DataSource
record
- DataRecord containing record values to be saved and old values.public void updateRecord(com.archibus.datasource.data.DataRecord record)
DataSource
updateRecord
in interface DataSource
record
- DataRecord containing record values to be saved.public void deleteRecord(com.archibus.datasource.data.DataRecord record)
DataSource
deleteRecord
in interface DataSource
record
- DataRecord containing record to be deleted.public void deleteRecord(java.util.Map fieldValues) throws com.archibus.utility.ExceptionBase
DataSource
deleteRecord
in interface DataSource
fieldValues
- map containing record values.com.archibus.utility.ExceptionBase
public com.archibus.datasource.data.DataRecord createRecord()
DataSource
createRecord
in interface DataSource
public com.archibus.datasource.data.DataRecord createNewRecord()
DataSource
createNewRecord
in interface DataSource
public com.archibus.datasource.data.DataRecord createRecordFromContext()
DataSource
createRecordFromContext
in interface DataSource
public com.archibus.datasource.data.DataRecord getDefaultRecord(java.lang.String restriction)
DataSource
getDefaultRecord
in interface DataSource
restriction
- Client-supplied restriction string, or null.public void executeUpdate()
DataSource
executeUpdate
in interface DataSource
public void executeUpdateRequired()
DataSource
executeUpdateRequired
in interface DataSource
public DataSource setMaxRecords(int maxRecords)
DataSource
setMaxRecords
in interface DataSource
maxRecords
- Positive number, or 0 to read all available records without limit.public boolean hasMoreRecords()
DataSource
hasMoreRecords
in interface DataSource
public java.lang.String createSqlForLastAddedPK(java.util.Map fieldValues)
fieldValues
- The PK values.public void checkSetContext()
public void commit()
DataSource
commit
in interface DataSource
public void rollback()
DataSource
rollback
in interface DataSource
protected void checkAutoCommit()
protected boolean useCascadeHandler()