Package com.isomorphic.jpa
Class JPADataSource
java.lang.Object
com.isomorphic.base.Base
com.isomorphic.datasource.DataSource
com.isomorphic.datasource.BasicDataSource
com.isomorphic.jpa.JPADataSource
- All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable,com.isomorphic.datasource.Committable,com.isomorphic.datasource.FreeResourcesHandler,com.isomorphic.datasource.IType,IToJSON,Serializable
- Direct Known Subclasses:
GAEJPADataSource,JPA2DataSource
Server side implementation of JPA 1.0 data source.
This class supports search with advanced criteria.
This class supports fields with 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 name
- Operating under RPCManager (
DSRequesthas reference toRPCManager):- If participates in automatic transactions:
- retrieves existing transaction from
RPCManager(if exists); - starts new transaction (if not found in
RPCManager);
- retrieves existing transaction from
- If one transaction per operation is used - starts new transaction;
- Registers itslef to
DSRequest.registerCallback()foronSuccess()/onFailure()execution to commit/roll back transaction; - Sets
DSRequest.setFreeOnExecute()tofalseto postpone releasing ofEntityManageravoiding lazy loading exceptions when creating JS response and traversing through persistent object tree; - Registers itslef to
RPCManager.registerFreeResourcesHandler()forfreeResources()execution to releaseEntityManager.
- If participates in automatic transactions:
- Operating without RPCManager:
- starts new transaction;
- commits/rolls back transaction and releases
EntityManagerifDSRequest.setFreeOnExecute()is set totrue(default); - relies on calling code to call
onSuccess()/onFailure()to commit/roll back transaction and to callfreeResources()to releaseEntityManager.
Example code for data source operation execution with manual transaction handling: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);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionHolds list of additional fields requested by specificDSRequest.static final StringName of the data source definition property holding should data source be auto derived.static final StringName of the data source definition property holding fully-qualified class name.protected ClassHolds class from the DataSource definition.protected StringHolds bean name - simple class name with preceding underscore.protected StringHolds config name - can be configured with "jpaConfig" parameter.protected JPAConnectionHolderHolds connection information for Automatic Transactions.protected jakarta.persistence.EntityManagerHolds entity manager for operations with underlying data.static final CharacterHolds character ('~') used to escape wild cards in 'like' clause.protected BooleanHolds value should related updates be generated.static final StringName of the data source definition property holding fully-qualified class name for composite primary key.protected ClassHolds id class from the DataSource definition.static final StringName of the JPA configuration name property.protected List<DSResponse>Holds list of generated related updates.static final StringName of the data source definition property holding should data source be auto derived from specified mapped entity.protected booleanFlag used to indicate that transaction should be rolled back.protected booleanIf set to true, advanced filtering will follow SQL99 behavior for dealing with NULL values, which is often counter-intuitive to users.protected ObjectHolds transaction object.static final StringName of property specifying should fully-qualified class name be used in query string.protected BooleanAccording to JPA specifications only simple class name can be used in queries.Fields inherited from class com.isomorphic.datasource.DataSource
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 -
Method Summary
Modifier and TypeMethodDescriptionCreates data source configuration from specified fully qualified class name.static StringescapeValueForFilter(Object value, char escapeChar) Escapes characters "_" and "%" with specified character in value object.This method carries out the actual processing of a DataSource request.executeAdd(DSRequest req) This method is called by DataSource.execute() for "add" operations.executeFetch(DSRequest req) This method is called by DataSource.execute() for "fetch" operations.executeRemove(DSRequest dsRequest) This method is called by DataSource.execute() for "remove" operations.executeUpdate(DSRequest req) This method is called by DataSource.execute() for "update" operations.voidfreeResources(DSRequest req) ClosesEntityManager.ReturnsDSFieldby specified name.getFieldNames(boolean dropIgnored) Returns combined list of data source configured and request configured field names.getTransactionObjectKey(boolean longForm) voidIncreases operations count by 1.voidvoidmarkTransactionForRollBack(DSResponse dsResponse) Sets flag that current transaction should be rolled back.Methods inherited from class com.isomorphic.datasource.BasicDataSource
getAuditDataSource, getAuditRecord, getAuditRecord, hasCustomDefaultFetchOperation, hasCustomLogic, shouldAutoJoinTransaction, shouldAutoStartTransaction, transformMultipleFields, transformMultipleFields, writeMultiAuditsMethods inherited from class com.isomorphic.datasource.DataSource
add, add, addDynamicDSGenerator, addDynamicDSGenerator, addDynamicDSGenerator, clearDynamicDSGenerators, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, convertRelativeDates, executeFileSource, fetch, fetch, fetchById, fetchById, fetchById, fetchSingle, fetchSingle, filter, filter, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, fromXML, get1ManyRelationFields, getAuditChangedFieldsFieldName, getAuditRevisionFieldName, getAuditTimestampFieldName, getAuditTypeFieldName, getAuditUserFieldName, getDefaultDynamicDSGenerator, getDirectFields, getDynamicDSGenerators, getEnumConstantProperty, getEnumOrdinalProperty, getEnumTranslateStrategy, getFieldNames, getFile, getFileAsInputStream, getFileAsString, getFileContentsField, getFileFormatField, getFileNameField, getFileTypeField, getID, getJoinDSName, getJoinDSName, getListProperties, getListProperties, getListProperty, getManyManyRelationFields, getMapProperty, getName, getNonIncludedFields, getObjectProperty, getOperationProperty, getPrimaryKey, getProperties, getProperties, getProperties, getProperty, getPropertyJavaClass, getRecordXPath, getRelatedDisplayRecord, getRelatedDisplayRecord, getRelatedDSName, getRelatedDSName, getRelatedTableAlias, getRelationFields, getTableName, getTransactionObject, getTransactionObject, has1ManyRelationFields, hasFile, hasManyManyRelationFields, hasRecord, hasRecord, hasRelationFields, initialized, is1ManyRelationField, isManyManyRelationField, isModificationOperation, isRelationField, isServerOnly, listFiles, listFiles, 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
-
Field Details
-
BEAN_CLASS_PROPERTY
Name of the data source definition property holding fully-qualified class name.- See Also:
-
AUTO_DERIVE_PROPERTY
Name of the data source definition property holding should data source be auto derived.- See Also:
-
SCHEMA_BEAN_PROPERTY
Name of the data source definition property holding should data source be auto derived from specified mapped entity.- See Also:
-
ID_CLASS_PROPERTY
Name of the data source definition property holding fully-qualified class name for composite primary key.- See Also:
-
ESCAPE_CHARACTER
Holds character ('~') used to escape wild cards in 'like' clause. Avoid using backslash '\' or dollar sign '$' because it is often used in databases as DB escape or wild card characters. -
JPA_CONFIG_PROPERTY
Name of the JPA configuration name property.- See Also:
-
configName
Holds config name - can be configured with "jpaConfig" parameter. Holds empty string for default configuration. -
beanClass
Holds class from the DataSource definition. -
beanName
Holds bean name - simple class name with preceding underscore. Defaults to "_beanName" if class is anonymous. Used in creating query. -
idClass
Holds id class from the DataSource definition. -
strictSQLFiltering
protected boolean strictSQLFilteringIf set to true, advanced filtering will follow SQL99 behavior for dealing with NULL values, which is often counter-intuitive to users. -
USE_QUALIFIED_CLASS_NAME_PROPERTY
Name of property specifying should fully-qualified class name be used in query string.- See Also:
-
useQualifiedClassName
According to JPA specifications only simple class name can be used in queries. Some providers follows these specs strictly (for example EclipseLink). Some providers allows using fully-qualified class name usage (for example Hibernate, Datanucleus). Setting defaults tofalse- simple class name usage. To resolve class name collisions this setting can be set totrue(should be used with provider supporting fully-qualified class name usage). -
em
protected jakarta.persistence.EntityManager emHolds entity manager for operations with underlying data. -
tx
Holds transaction object. -
shouldRollBackTransaction
protected boolean shouldRollBackTransactionFlag used to indicate that transaction should be rolled back. -
connectionHolder
Holds connection information for Automatic Transactions. -
additionalFields
Holds list of additional fields requested by specificDSRequest. -
generateRelatedUpdates
Holds value should related updates be generated. (Re)initialized on everyexecute()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.
-
-
Method Details
-
init
- Throws:
Exception
-
deriveDS
Creates data source configuration from specified fully qualified class name.- Parameters:
schemaBean-StringFully qualified class name.id-StringId for newly created data source.extended-booleanExtended properties will be captured if set totrue.- Returns:
Map<String, Object>created data source configuration ornullif it can not be created.
-
getFieldNames
Returns combined list of data source configured and request configured field names.- Parameters:
dropIgnored-booleantrue- ignored fields are dropped;false- ignored fields are included;- Returns:
Listfield names.
-
getField
ReturnsDSFieldby specified name. First checks data source configured fields. Checks request configured fields if it is not found within data source configured fields. ReturnsnulliffieldNameparameter isnullor field is not found.- Overrides:
getFieldin classBasicDataSource- Parameters:
fieldName- the name of the field whose definition you want- Returns:
DSFieldfield.- See Also:
-
execute
This method carries out the actual processing of a DataSource request. It can be overridden to provide centralized logic that applies to all operation types (such as transaction management, for example), or to implement special validation rules that cannot be handled by the built-in validation system. Generally, however, it is more appropriate to override the method specific to the operationType - executeFetch(), executeRemove(), executeAdd(), executeUpdate() or executeCustom(). Note that you must call the validate() method to retain correct validation behavior if you override this method and do not invoke super() This method is also the place where the transform happens if dataSourceField.multipleStorage is used. The transform is performed by two methods,DataSource.transformMultipleFields(DSRequest)andDataSource.transformMultipleFields(DSResponse).- Overrides:
executein classDataSource- Parameters:
req- The DSRequest object representing this operation- Returns:
- A valid DSResponse
- Throws:
Exception- if an error occurs during request execution
-
executeFetch
This method is called by DataSource.execute() for "fetch" operations. It is the appropriate override point if you wish to provide custom handling of a "fetch".- Overrides:
executeFetchin classDataSource- Parameters:
req- The DSRequest object representing this operation- Returns:
- A valid DSResponse
- Throws:
Exception- if an error occurs during the fetch operation
-
executeAdd
This method is called by DataSource.execute() for "add" operations. It is the appropriate override point if you wish to provide custom handling of an "add".- Overrides:
executeAddin classDataSource- Parameters:
req- The DSRequest object representing this operation- Returns:
- A valid DSResponse
- Throws:
Exception- if an error occurs during the add operation
-
executeRemove
This method is called by DataSource.execute() for "remove" operations. It is the appropriate override point if you wish to provide custom handling of a "remove".- Overrides:
executeRemovein classDataSource- Parameters:
dsRequest- The DSRequest object representing this operation- Returns:
- A valid DSResponse
- Throws:
Exception- if an error occurs during the remove operation
-
executeUpdate
This method is called by DataSource.execute() for "update" operations. It is the appropriate override point if you wish to provide custom handling of an "update".- Overrides:
executeUpdatein classDataSource- Parameters:
req- The DSRequest object representing this operation- Returns:
- A valid DSResponse
- Throws:
Exception- if an error occurs during the update operation
-
escapeValueForFilter
Escapes characters "_" and "%" with specified character in value object. Specified escape character is escaped (doubled) as well. Empty string is returned if value object is null.- Parameters:
value-ObjectValue which should be escaped.escapeChar-charescape character.- Returns:
StringEscaped string value.
-
markTransactionForRollBack
Sets flag that current transaction should be rolled back. IfDSResponseis provided - sets it's status to failure.- Parameters:
dsResponse-DSResponsestatus will be set to failure if provided. Can benull.
-
freeResources
ClosesEntityManager. When participating in automatic transactions - closesEntityManagerstored inconnectionHolderobject. IfconnectionHolderis not initialized (meaning we did not participate in automatic transaction) - closes currentEntityManager. -
getTransactionObjectKey
-
increaseOpCount
public void increaseOpCount()Increases operations count by 1. Used to update statistics for Automatic Transactions.
-