public class JPADataSource extends BasicDataSource
valueXPath
setting. Entity property is accessed (by priority):valueXPath
- supports only simple XPath definitions: "property/subProperty/subSubProperty"name
- most often used when data source field name is the same as entity property nameDSRequest
has reference to RPCManager
):RPCManager
(if exists);RPCManager
);DSRequest.registerCallback()
for onSuccess()
/ onFailure()
execution to commit/roll back transaction;DSRequest.setFreeOnExecute()
to false
to postpone releasing of EntityManager
avoiding lazy loading exceptions when creating JS response and traversing through persistent object tree;RPCManager.registerFreeResourcesHandler()
for freeResources()
execution to release EntityManager
.EntityManager
if DSRequest.setFreeOnExecute()
is set to true
(default);onSuccess()
/onFailure()
to commit/roll back transaction and to call freeResources()
to release EntityManager
.DSRequest req = new DSRequest("myDS", "fetch"); req.setFreeOnExecute(false); DSResponse resp = req.execute(); List dataList = resp.getDataList(); //... traverse through persistent object tree // Commit current transaction. ((JPADataSource) r.getDataSource()).onSuccess(); // Release entity manager. ((JPADataSource) r.getDataSource()).freeResources(req);
Modifier and Type | Field and Description |
---|---|
protected java.util.Map | additionalFields Holds list of additional fields requested by specific DSRequest . |
static java.lang.String | AUTO_DERIVE_PROPERTY Name of the data source definition property holding should data source be auto derived. |
static java.lang.String | BEAN_CLASS_PROPERTY Name of the data source definition property holding fully-qualified class name. |
protected java.lang.Class | beanClass Holds class from the DataSource definition. |
protected java.lang.String | beanName Holds bean name - simple class name with preceding underscore. |
protected java.lang.String | configName Holds config name - can be configured with "jpaConfig" parameter. |
protected JPAConnectionHolder | connectionHolder Holds connection information for Automatic Transactions. |
protected EntityManager | em Holds entity manager for operations with underlying data. |
static java.lang.Character | ESCAPE_CHARACTER Holds character ('~') used to escape wild cards in 'like' clause. |
protected java.lang.Boolean | generateRelatedUpdates Holds value should related updates be generated. |
static java.lang.String | ID_CLASS_PROPERTY Name of the data source definition property holding fully-qualified class name for composite primary key. |
protected java.lang.Class | idClass Holds id class from the DataSource definition. |
static java.lang.String | JPA_CONFIG_PROPERTY Name of the JPA configuration name property. |
protected java.util.List | relatedUpdates Holds list of generated related updates. |
static java.lang.String | SCHEMA_BEAN_PROPERTY Name of the data source definition property holding should data source be auto derived from specified mapped entity. |
protected boolean | shouldRollBackTransaction Flag used to indicate that transaction should be rolled back. |
protected boolean | strictSQLFiltering If set to true, advanced filtering will follow SQL99 behavior for dealing with NULL values, which is often counter-intuitive to users. |
protected java.lang.Object | tx Holds transaction object. |
static java.lang.String | USE_QUALIFIED_CLASS_NAME_PROPERTY Name of property specifying should fully-qualified class name be used in query string. |
protected java.lang.Boolean | useQualifiedClassName According to JPA specifications only simple class name can be used in queries. |
OP_ADD, OP_CLIENT_EXPORT, OP_CUSTOM, OP_DOWNLOAD_FILE, OP_FETCH, OP_GET_FILE, OP_GET_FILE_VERSION, OP_HAS_FILE, OP_HAS_FILE_VERSION, OP_LIST_FILE_VERSIONS, OP_LIST_FILES, OP_LOAD_SCHEMA, OP_REMOVE, OP_REMOVE_FILE, OP_REMOVE_FILE_VERSION, OP_RENAME_FILE, OP_SAVE_FILE, OP_UNIQUE_NAME, OP_UPDATE, OP_VALIDATE, OP_VIEW_FILE
Modifier and Type | Method and Description |
---|---|
java.util.Map | deriveDS(java.lang.String schemaBean, java.lang.String id, boolean extended) Creates data source configuration from specified fully qualified class name. |
static java.lang.String | escapeValueForFilter(java.lang.Object value, char escapeChar) Escapes characters "_" and "%" with specified character in value object. |
DSResponse | execute(DSRequest req) This method carries out the actual processing of a DataSource request. |
DSResponse | executeAdd(DSRequest req) This method is called by DataSource.execute() for "add" operations. |
DSResponse | executeFetch(DSRequest req) This method is called by DataSource.execute() for "fetch" operations. |
DSResponse | executeRemove(DSRequest dsRequest) This method is called by DataSource.execute() for "remove" operations. |
DSResponse | executeUpdate(DSRequest req) This method is called by DataSource.execute() for "update" operations. |
void | freeResources(DSRequest req) Closes EntityManager . |
DSField | getField(java.lang.String fieldName) Returns DSField by specified name. |
java.util.List | getFieldNames(boolean dropIgnored) Returns combined list of data source configured and request configured field names. |
java.lang.String | getTransactionObjectKey(boolean longForm) Returns the key used to store the current transaction object for this DataSource and other DataSources of the same type and provider. |
void | increaseOpCount() Increases operations count by 1. |
void | init(java.util.Map theConfig, DSRequest dsRequest) |
void | markTransactionForRollBack(DSResponse dsResponse) Sets flag that current transaction should be rolled back. |
getAuditDataSource, getAuditRecord, getAuditRecord, hasCustomDefaultFetchOperation, hasCustomLogic, shouldAutoJoinTransaction, shouldAutoStartTransaction, transformMultipleFields, transformMultipleFields, writeMultiAudits
add, add, addDynamicDSGenerator, addDynamicDSGenerator, addDynamicDSGenerator, clearDynamicDSGenerators, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, executeClientExport, executeCustom, executeFileSource, fetch, fetch, fetchById, fetchById, fetchById, fetchSingle, fetchSingle, filter, filter, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, getAuditChangedFieldsFieldName, getAuditRevisionFieldName, getAuditTimestampFieldName, getAuditTypeFieldName, getAuditUserFieldName, getDefaultDynamicDSGenerator, getDirectFields, getDynamicDSGenerators, getEnumConstantProperty, getEnumOrdinalProperty, getEnumTranslateStrategy, getFieldNames, getFile, getFileAsInputStream, getFileAsString, getFileContentsField, getFileFormatField, getFileNameField, getFileTypeField, getID, getListProperties, getListProperties, getListProperty, getMapProperty, getName, getNonIncludedFields, getObjectProperty, getOperationProperty, getPrimaryKey, getProperties, getProperties, getProperties, getProperty, getPropertyJavaClass, getRecordXPath, getRelatedDisplayRecord, getRelatedDisplayRecord, getRelatedTableAlias, getTableName, getTransactionObject, getTransactionObject, hasFile, hasRecord, hasRecord, initialized, isModificationOperation, isServerOnly, listFiles, listFiles, listFiles, listFiles, remove, removeDynamicDSGenerator, removeDynamicDSGenerator, removeDynamicDSGenerator, removeFile, renameFile, saveFile, setEnumConstantProperty, setEnumOrdinalProperty, setEnumTranslateStrategy, setOmitNullMapValuesInResponse, setProperties, transformImportValue, transformImportValue, transformResponse, update, update, validate, validate, validate, validateRecord
public static final java.lang.String BEAN_CLASS_PROPERTY
public static final java.lang.String AUTO_DERIVE_PROPERTY
public static final java.lang.String SCHEMA_BEAN_PROPERTY
public static final java.lang.String ID_CLASS_PROPERTY
public static final java.lang.Character ESCAPE_CHARACTER
public static final java.lang.String JPA_CONFIG_PROPERTY
protected java.lang.String configName
protected java.lang.Class beanClass
protected java.lang.String beanName
protected java.lang.Class idClass
protected boolean strictSQLFiltering
public static final java.lang.String USE_QUALIFIED_CLASS_NAME_PROPERTY
protected java.lang.Boolean useQualifiedClassName
false
- simple class name usage. To resolve class name collisions this setting can be set to true
(should be used with provider supporting fully-qualified class name usage).protected EntityManager em
protected java.lang.Object tx
protected boolean shouldRollBackTransaction
protected JPAConnectionHolder connectionHolder
protected java.util.Map additionalFields
DSRequest
.protected java.util.List relatedUpdates
setProperties()
; subsequent calls to setRelationFieldValue()
will add DSResponse
objects for every change in related data sources.protected java.lang.Boolean generateRelatedUpdates
execute()
call. true
- related updates will be generated; false
- related updates will not be generated; null
- related updates will be generated only for "add" and "update" operations, related updates will not be generated for "remove" operation.public void init(java.util.Map theConfig, DSRequest dsRequest) throws java.lang.Exception
init
in class BasicDataSource
java.lang.Exception
public java.util.Map deriveDS(java.lang.String schemaBean, java.lang.String id, boolean extended)
schemaBean
- String
Fully qualified class name.id
- String
Id for newly created data source.extended
- boolean
Extended properties will be captured if set to true
.Map<String, Object>
created data source configuration or null
if it can not be created.public java.util.List getFieldNames(boolean dropIgnored)
getFieldNames
in class DataSource
dropIgnored
- boolean
true
- ignored fields are dropped; false
- ignored fields are included;List
field names.public DSField getField(java.lang.String fieldName)
DSField
by specified name. First checks data source configured fields. Checks request configured fields if it is not found within data source configured fields. Returns null
if fieldName
parameter is null
or field is not found.getField
in class BasicDataSource
fieldName
- the name of the field whose definition you wantDSField
field.DSField
public DSResponse execute(DSRequest req) throws java.lang.Exception
DataSource
DataSource.transformMultipleFields(DSRequest)
and DataSource.transformMultipleFields(DSResponse)
.execute
in class DataSource
req
- The DSRequest object representing this operationjava.lang.Exception
public DSResponse executeFetch(DSRequest req) throws java.lang.Exception
DataSource
executeFetch
in class DataSource
req
- The DSRequest object representing this operationjava.lang.Exception
public DSResponse executeAdd(DSRequest req) throws java.lang.Exception
DataSource
executeAdd
in class DataSource
req
- The DSRequest object representing this operationjava.lang.Exception
public DSResponse executeRemove(DSRequest dsRequest) throws java.lang.Exception
DataSource
executeRemove
in class DataSource
dsRequest
- The DSRequest object representing this operationjava.lang.Exception
public DSResponse executeUpdate(DSRequest req) throws java.lang.Exception
DataSource
executeUpdate
in class DataSource
req
- The DSRequest object representing this operationjava.lang.Exception
public static java.lang.String escapeValueForFilter(java.lang.Object value, char escapeChar)
value
- Object
Value which should be escaped.escapeChar
- char
escape character.String
Escaped string value.public void markTransactionForRollBack(DSResponse dsResponse)
DSResponse
is provided - sets it's status to failure.dsResponse
- DSResponse
status will be set to failure if provided. Can be null
.public void freeResources(DSRequest req)
EntityManager
. When participating in automatic transactions - closes EntityManager
stored in connectionHolder
object. If connectionHolder
is not initialized (meaning we did not participate in automatic transaction) - closes current EntityManager
.freeResources
in class DataSource
public java.lang.String getTransactionObjectKey(boolean longForm)
DataSource
This method is part of the Automatic Transactions feature, which is effective only in Power edition and above.
getTransactionObjectKey
in class DataSource
public void increaseOpCount()