public class JPADataSource extends BasicDataSource implements RPCManagerCompletionCallback
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 javax.persistence.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. |
inInitState, OP_ADD, OP_CLIENT_EXPORT, OP_CUSTOM, OP_FETCH, OP_FILE_SOURCE, OP_GET_FILE, OP_HAS_FILE, OP_LIST_FILES, OP_REMOVE, OP_REMOVE_FILE, OP_RENAME_FILE, OP_SAVE_FILE, OP_UPDATE, OP_VALIDATE| 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) |
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. |
void | onFailure(boolean transactionFailed) Rolls back current transaction. |
void | onFailure(RPCManager rpc, boolean transactionFailed) Implementation of RPCManagerCompletionCallback.onFailure(). |
void | onSuccess() Commits current transaction. |
void | onSuccess(RPCManager rpc) Implementation of RPCManagerCompletionCallback.onSuccess(). |
getAuditDataSource, getProperty, shouldAutoJoinTransaction, shouldAutoStartTransaction, transformMultipleFields, transformMultipleFieldsadd, addDynamicDSGenerator, addDynamicDSGenerator, addDynamicDSGenerator, clearDynamicDSGenerators, executeClientExport, executeCustom, executeFileSource, fetch, fetch, fetchById, fetchSingle, fetchSingle, filter, filter, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, getAuditRevisionFieldName, getAuditTimestampFieldName, getAuditTypeFieldName, getAuditUserFieldName, getDefaultDynamicDSGenerator, getDynamicDSGenerators, getEnumConstantProperty, getEnumOrdinalProperty, getEnumTranslateStrategy, getFieldNames, getFile, getFileAsInputStream, getFileAsString, getFileContentsField, getFileFormatField, getFileNameField, getFileTypeField, getListProperties, getListProperties, getPrimaryKey, getProperties, getProperties, getProperties, getPropertyJavaClass, getRecordXPath, getTransactionObject, getTransactionObject, hasFile, hasRecord, hasRecord, initialized, isModificationOperation, isServerOnly, listFiles, listFiles, remove, removeDynamicDSGenerator, removeDynamicDSGenerator, removeDynamicDSGenerator, removeFile, renameFile, saveFile, setEnumConstantProperty, setEnumOrdinalProperty, setEnumTranslateStrategy, setProperties, update, validatepublic 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 javax.persistence.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 java.lang.Exceptionpublic 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)
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.DSField field.public DSResponse execute(DSRequest req) throws java.lang.Exception
DataSourcecom.isomorphic.datasource.DataSource.transformMultipleFields(DSRequest) and com.isomorphic.datasource.DataSource.transformMultipleFields(DSResponse).execute in class DataSourcereq - The DSRequest object representing this operationjava.lang.Exceptionpublic DSResponse executeFetch(DSRequest req) throws java.lang.Exception
DataSourceexecuteFetch in class DataSourcereq - The DSRequest object representing this operationjava.lang.Exceptionpublic DSResponse executeAdd(DSRequest req) throws java.lang.Exception
DataSourceexecuteAdd in class DataSourcereq - The DSRequest object representing this operationjava.lang.Exceptionpublic DSResponse executeRemove(DSRequest dsRequest) throws java.lang.Exception
DataSourceexecuteRemove in class DataSourcedsRequest - The DSRequest object representing this operationjava.lang.Exceptionpublic DSResponse executeUpdate(DSRequest req) throws java.lang.Exception
DataSourceexecuteUpdate in class DataSourcereq - The DSRequest object representing this operationjava.lang.Exceptionpublic 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.public java.lang.String getTransactionObjectKey(boolean longForm)
public void onSuccess()
throws java.lang.Exception java.lang.Exception - when commit fails.public void onSuccess(RPCManager rpc) throws java.lang.Exception
connectionHolder object. If connectionHolder is not initialized (meaning we did not participate in automatic transaction) - commits current transaction.onSuccess in interface RPCManagerCompletionCallbackrpc - RPCManager which manages transactions.java.lang.Exception - when commit fails.public void onFailure(boolean transactionFailed)
transactionFailed - boolean true if failure happened while committing current transaction; otherwise false.public void onFailure(RPCManager rpc, boolean transactionFailed) throws java.lang.Exception
connectionHolder object. If connectionHolder is not initialized (meaning we did not participate in automatic transaction) - rolls back current transaction.onFailure in interface RPCManagerCompletionCallbackrpc - RPCManager which manages transactions.transactionFailed - boolean true if at least one failure happened in a request that was being managed by a user-provided or automatic transaction; otherwise false.java.lang.Exception - when roll back fails.public void increaseOpCount()