|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface 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.
| Nested Class Summary | |
|---|---|
static interface |
DataSource.RecordHandler
Callback interface that can be passed as a parameter to getRecords() and getAllRecords(). |
| Field Summary | |
|---|---|
static java.lang.String |
DATA_TYPE_DATE
Constant for date field/parameter type. |
static java.lang.String |
DATA_TYPE_INTEGER
Constant for integer field/parameter type. |
static java.lang.String |
DATA_TYPE_MEMO
Constant for memo field/parameter type. |
static java.lang.String |
DATA_TYPE_NUMBER
Constant for numeric field/parameter type. |
static java.lang.String |
DATA_TYPE_TEXT
Constant for text field/parameter type. |
static java.lang.String |
DATA_TYPE_TIME
Constant for time field/parameter type. |
static java.lang.String |
DATA_TYPE_VERBATIM
Constant for unformatted (verbatim) parameter type. |
static java.lang.String |
DB_ROLE_DATA
Constant for "data" database role. |
static java.lang.String |
DB_ROLE_SCHEMA
Constant for "schema" database role. |
static java.lang.String |
DB_ROLE_SECURITY
Constant for "security" database role. |
static java.lang.String |
ROLE_MAIN
Constant for "main" table role. |
static java.lang.String |
ROLE_STANDARD
Constant for "standard" table role. |
static java.lang.String |
SORT_ASC
Constant for ascending sort order. |
static java.lang.String |
SORT_DESC
Constant for descending sort order. |
| Method Summary | |
|---|---|
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. |
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(Restrictions.Restriction.Clause c)
Adds a restriction clause. |
DataSource |
addRestriction(Restrictions.Restriction r)
Adds a restriction. |
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)
|
DataSource |
clearRestrictions()
Clears all restrictions defined in AXVW. |
void |
commit()
Commit current database transaction. |
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. |
DataRecord |
createRecord()
Creates new DataRecord with default values for all fields defined in the data source. |
DataRecord |
createRecordFromContext()
Creates new DataRecord with default values for all fields defined in the data source. |
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(DataRecord record)
Deletes existing record. |
void |
deleteRecord(java.util.Map fieldValues)
Deletes record specified by field values. |
void |
executeUpdate()
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 |
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 |
formatSqlForPersistentRestrictions()
Formats SQL expression that includes VPA and hierarchical security restrictions. |
java.lang.String |
formatSqlQuery(java.lang.String restriction,
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 restriction,
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.util.List<com.archibus.db.ViewField.Immutable> |
getAllFields()
Returns a list of field definitions for visible and/or virtual fields. |
java.util.List<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 tableName,
java.lang.String fieldName)
Returns specified virtual field definition. |
java.util.List<EventHandlerBase.DbField> |
getDbFieldsForNewRecord()
Returns a list of DB field definitions for default new record. |
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. |
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. |
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 al custom queries. |
DataRecord |
getRecord()
Retrieves a single record that contains values for all fields defined in the data source. |
DataRecord |
getRecord(java.lang.String restriction)
Retrieves a single record that contains values for all fields defined in the data source. |
java.util.List<DataRecord> |
getRecords()
Retrieves records that contains values for all fields defined in the data source. |
java.util.List<DataRecord> |
getRecords(java.lang.String restriction)
Retrieves records that contains values for all fields defined in the data source. |
java.util.List<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()
|
com.archibus.datasource.VirtualFieldDef |
getVirtualFieldDef(java.lang.String tableName,
java.lang.String fieldName)
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 |
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.RestrictionBase.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. |
DataRecord |
saveRecord(DataRecord record)
Saves new or updates existing record. |
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. |
DataSource |
setDistinct(boolean isDistinct)
Sets isDistinct flag. |
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 |
setTitle(java.lang.String title)
|
DataSource |
setUseHierarchicalSecurityRestriction(boolean useHierarchicalSecurityRestriction)
Sets the useHierarchicalSecurityRestriction property. |
| Field Detail |
|---|
static final java.lang.String DB_ROLE_DATA
static final java.lang.String DB_ROLE_SCHEMA
static final java.lang.String DB_ROLE_SECURITY
static final java.lang.String ROLE_MAIN
static final java.lang.String ROLE_STANDARD
static final java.lang.String SORT_ASC
static final java.lang.String SORT_DESC
static final java.lang.String DATA_TYPE_TEXT
static final java.lang.String DATA_TYPE_NUMBER
static final java.lang.String DATA_TYPE_INTEGER
static final java.lang.String DATA_TYPE_DATE
static final java.lang.String DATA_TYPE_TIME
static final java.lang.String DATA_TYPE_MEMO
static final java.lang.String DATA_TYPE_VERBATIM
| Method Detail |
|---|
DataSource setDatabaseRole(java.lang.String role)
role - java.util.List<java.lang.String> getFieldNames()
java.lang.String getTitle()
void setTitle(java.lang.String title)
title - the title to setjava.lang.String getId()
void setId(java.lang.String id)
id - the id to setDataSource addTable(java.lang.String name)
name - Table name, i.e. "wr".
DataSource addTable(java.lang.String name,
java.lang.String role)
name - Table name, i.e. "wr".role - Table role, i.e. "standard".DataSource addField(java.lang.String name)
name - Field name, i.e. "status".DataSource addField(java.lang.String[] names)
names - Array of field names.
DataSource addField(java.lang.String table,
java.lang.String name)
table - Table name, i.e. "wr".name - Field name, i.e. "status".
DataSource addField(java.lang.String table,
java.lang.String[] names)
table - Table name, i.e. "wr".names - Array of field names.DataSource addSort(java.lang.String name)
name - Field name, i.e. "status".
DataSource addSort(java.lang.String table,
java.lang.String name)
table - Table name, i.e. "wr".name - Field name, i.e. "status".
DataSource addSort(java.lang.String table,
java.lang.String name,
java.lang.String order)
table - Table name, i.e. "wr".name - Field name, i.e. "status".order - Sort order: asc|desc.
DataSource addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType)
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.
DataSource addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType,
int size,
int decimals)
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.
DataSource addVirtualField(java.lang.String table,
java.lang.String name,
java.lang.String dataType,
int size,
int decimals,
java.lang.String title)
DataSource addCalculatedField(com.archibus.datasource.VirtualFieldDef calculatedField)
calculatedField -
DataSource addQuery(java.lang.String sql)
sql -
DataSource addQuery(java.lang.String sql,
java.lang.String dialect)
sql - dialect - SQL dialect: generic|sybase|oracle|sqlservercom.archibus.datasource.SqlExpressions getQueries()
DataSource addParameter(java.lang.String name,
java.lang.String value,
java.lang.String dataType)
name - Parameter name.value - Parameter value.dataType - Parameter type, used to parse the value into an object.
DataSource addParameter(java.lang.String name,
java.lang.Object value,
java.lang.String dataType)
DataSource addParameter(java.lang.String name,
int value,
java.lang.String dataType)
DataSource addParameter(java.lang.String name,
double value,
java.lang.String dataType)
java.util.Map<java.lang.String,DataSourceImpl.Parameter> getParameters()
DataSource addRestriction(Restrictions.Restriction r)
r - Restriction.DataSource addRestriction(Restrictions.Restriction.Clause c)
c - Restriction clause.DataSource clearRestrictions()
DataSource setDistinct(boolean isDistinct)
isDistinct - DataSource setUseHierarchicalSecurityRestriction(boolean useHierarchicalSecurityRestriction)
useHierarchicalSecurityRestriction - DataSource setAutoCommit(boolean autoCommit)
autoCommit -
com.archibus.db.ViewField.Immutable createVirtualViewField(java.lang.String table,
java.lang.String name,
java.lang.String fieldJavaType,
java.text.NumberFormat format)
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.
DataSource setParameter(java.lang.String name,
java.lang.Object value)
name - value - DataSource setContext(com.archibus.config.ContextCacheable.Immutable context)
context - Web Central context object, typically a UserSession.DataSource setContext(EventHandlerContext eventHandlerContext)
eventHandlerContext - WFR event handler context.DataSource setContext()
java.util.List<DataSourceImpl.TableAndRole> getTablesAndRoles()
java.util.List<com.archibus.db.ViewField.Immutable> getVisibleFields()
java.util.List<com.archibus.db.ViewField.Immutable> getVirtualFields()
com.archibus.datasource.VirtualFieldDef getVirtualFieldDef(java.lang.String tableName,
java.lang.String fieldName)
tableName - fieldName -
com.archibus.datasource.VirtualFieldDef getCalculatedFieldDef(java.lang.String tableName,
java.lang.String fieldName)
tableName - fieldName -
java.util.Map<java.lang.String,com.archibus.db.ViewField.Immutable> getVisibleFieldsByName()
java.util.List<Restrictions.Restriction> getRestrictions()
java.util.Map<java.lang.String,java.lang.Object> getRestrictionValues()
java.util.List<DataSourceImpl.SortField> getSortFields()
java.lang.String getMainTableName()
com.archibus.schema.TableDef.ThreadSafe getMainTableDef()
java.util.List<java.lang.String> getPrimaryKeyFieldNamesForTable(java.lang.String tableName)
boolean hasCustomQuery()
boolean hasVirtualFields()
java.util.List<com.archibus.db.ViewField.Immutable> getPrimaryKeyFields()
com.archibus.db.ViewField.Immutable findField(java.lang.String fullName)
fullName - Full field name, i.e. "wr.status".
com.archibus.db.ViewField.Immutable findVirtualField(java.lang.String fullName)
fullName - Full field name, i.e. "wr.status".
java.util.List<EventHandlerBase.DbField> getDbFieldsForVisibleFields()
java.util.List<com.archibus.db.ViewField.Immutable> getAllFields()
java.util.List<EventHandlerBase.DbField> getDbFieldsForNewRecord()
java.util.Map<java.lang.String,EventHandlerBase.DbField> getDbFieldsForPrimaryKeysAsMap()
org.json.JSONArray createPrimaryKeyIds()
boolean isSqlServer()
boolean isOracle()
boolean isSybase()
java.util.List<com.archibus.db.RestrictionBase.Immutable> parseClientRestrictions(java.lang.String restrictionString)
restrictionString - can contain: - single XML record; - single JSON record; - multiple
JSON records; - literal SQL expression;
java.lang.String formatSqlQuery(java.lang.String restriction,
boolean doNotWrap)
restriction - String containing client-side restriction in JSON format.doNotWrap - TODO
java.lang.String formatSqlQuery(java.lang.String restriction,
java.util.List sortValues,
java.util.List filterValues,
boolean isOrderbyAllowed,
boolean doNotWrap)
restriction - String containing client-side restriction in JSON format.sortValues - filterValues - isOrderbyAllowed - doNotWrap - TODO
java.lang.String formatSqlForPersistentRestrictions()
DataRecord getRecord()
DataRecord getRecord(java.lang.String restriction)
java.util.List<DataRecord> getRecords()
java.util.List<DataRecord> getRecords(java.lang.String restriction)
restriction - Client-supplied restriction string, or null.
java.util.List<DataRecord> getAllRecords()
void queryRecords(DataSource.RecordHandler recordHandler)
recordHandler -
void queryRecords(java.lang.String restriction,
DataSource.RecordHandler recordHandler)
recordHandler - DataRecord saveRecord(DataRecord record)
record - DataRecord containing record values to be saved and old values.
void deleteRecord(DataRecord record)
record - DataRecord containing record to be deleted.void deleteRecord(java.util.Map fieldValues)
fieldValues - MapDataRecord createRecord()
DataRecord createNewRecord()
DataRecord createRecordFromContext()
DataRecord getDefaultRecord(java.lang.String restriction)
restriction - Client-supplied restriction string, or null.
void executeUpdate()
DataSource setMaxRecords(int maxRecords)
maxRecords - Positive number, or 0 to read all available records without limit.boolean hasMoreRecords()
void commit()
void rollback()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||