-
Notifications
You must be signed in to change notification settings - Fork 1
Feature 296385 caching 1 #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: SandboxEnv
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,9 @@ | |
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.cache.annotation.CacheEvict; | ||
| import org.springframework.cache.annotation.Cacheable; | ||
| import org.springframework.context.annotation.Lazy; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
|
|
@@ -92,6 +95,18 @@ | |
| @Service("dataschemaService") | ||
| public class DataschemaServiceImpl implements DatasetSchemaService { | ||
|
|
||
| /** | ||
| * Self-referencing proxy of this service bean, injected to enable Spring AOP features | ||
| * (e.g., {@link Cacheable}, {@link CacheEvict}) on internal method calls within the same class. | ||
| * Direct {@code this.method()} calls bypass the Spring proxy and would not trigger cache | ||
| * interception; calling {@code self.method()} routes through the proxy instead. | ||
| * | ||
| * The {@link Lazy} annotation prevents circular dependency issues during bean initialization. | ||
| */ | ||
| @Autowired | ||
| @Lazy | ||
| private DatasetSchemaService self; | ||
|
|
||
| /** The Constant REGEX_NAME: {@value}. */ | ||
| private static final String REGEX_NAME = "[a-zA-Z0-9\\s_-]+"; | ||
|
|
||
|
|
@@ -333,21 +348,6 @@ public ObjectId createEmptyDataSetSchema(Long dataflowId) throws EEAException { | |
| return idDataSetSchema; | ||
| } | ||
|
|
||
| /** | ||
| * Delete group and remove user. | ||
| * | ||
| * @param datasetId the dataset id | ||
| * @param resourceTypeEnum the resource type enum | ||
| */ | ||
| @Override | ||
| public void deleteGroup(Long datasetId, ResourceTypeEnum resourceTypeEnum) { | ||
| // We find all types of data of this schema and delete it | ||
| List<ResourceInfoVO> resourceCustodian = resourceManagementControllerZull | ||
| .getGroupsByIdResourceType(datasetId, ResourceTypeEnum.DATA_SCHEMA); | ||
| resourceManagementControllerZull.deleteResource(resourceCustodian); | ||
| LOG.info("Deleted group for datasetId {}", datasetId); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the data schema by id. | ||
| * | ||
|
|
@@ -370,6 +370,21 @@ public DataSetSchemaVO getDataSchemaById(String dataschemaId) { | |
| return dataSchemaVO; | ||
| } | ||
|
|
||
| /** | ||
| * Delete group and remove user. | ||
| * | ||
| * @param datasetId the dataset id | ||
| * @param resourceTypeEnum the resource type enum | ||
| */ | ||
| @Override | ||
| public void deleteGroup(Long datasetId, ResourceTypeEnum resourceTypeEnum) { | ||
| // We find all types of data of this schema and delete it | ||
| List<ResourceInfoVO> resourceCustodian = resourceManagementControllerZull | ||
| .getGroupsByIdResourceType(datasetId, ResourceTypeEnum.DATA_SCHEMA); | ||
| resourceManagementControllerZull.deleteResource(resourceCustodian); | ||
| LOG.info("Deleted group for datasetId {}", datasetId); | ||
| } | ||
|
|
||
| /** | ||
| * Find the dataschema per idDataFlow. | ||
| * | ||
|
|
@@ -420,6 +435,7 @@ private void setNameSchema(String schemaId, DataSetSchemaVO dataschemaVO) { | |
| * @throws EEAException the EEA exception | ||
| */ | ||
| @Override | ||
| @Cacheable(value = "datasetSchemaId", key = "#datasetId") | ||
| public String getDatasetSchemaId(Long datasetId) throws EEAException { | ||
| return obtainDatasetMetabase(datasetId).getDatasetSchema(); | ||
| } | ||
|
|
@@ -450,6 +466,7 @@ private DataSetMetabase obtainDatasetMetabase(final Long datasetId) throws EEAEx | |
| */ | ||
| @Override | ||
| @Transactional | ||
| @CacheEvict(value = "datasetSchemaId", key = "#datasetId") | ||
| public void deleteDatasetSchema(String schemaId, Long datasetId) { | ||
| // we delete the integrity rules associated with this dataset and delete the integrity in mongo | ||
| rulesControllerZuul.deleteDatasetRuleAndIntegrityByDatasetSchemaId(schemaId, datasetId); | ||
|
|
@@ -568,7 +585,7 @@ public TableSchemaVO createTableSchema(String id, TableSchemaVO tableSchemaVO, L | |
| @Override | ||
| public void updateTableSchema(Long datasetId, TableSchemaVO tableSchemaVO, Boolean updateMaterializedViews) throws EEAException { | ||
|
|
||
| String datasetSchemaId = getDatasetSchemaId(datasetId); | ||
| String datasetSchemaId = self.getDatasetSchemaId(datasetId); | ||
|
|
||
| try { | ||
| Document tableSchema = | ||
|
|
@@ -777,6 +794,7 @@ public String createFieldSchema(String datasetSchemaId, FieldSchemaVO fieldSchem | |
| * @throws EEAException the EEA exception | ||
| */ | ||
| @Override | ||
| @Transactional | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transaction will not work for the invocation of this method on lines 2998 and 3390 of this class as they are not called through the self reference. Is this intentional? We don't want it to work there?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is surely not intentional. We do want
Both are private methods, and neither routes through self, so the Those calls should be routed through self otherwise:
|
||
| public DataType updateFieldSchema(String datasetSchemaId, FieldSchemaVO fieldSchemaVO, | ||
| Long datasetId, boolean cloningOrImporting) throws EEAException { | ||
|
|
||
|
|
@@ -1156,6 +1174,7 @@ public void updateDatasetSchemaDescription(String datasetSchemaId, String descri | |
| * @param availableInPublic the available in public | ||
| */ | ||
| @Override | ||
| @Transactional | ||
| public void updateDatasetSchemaExportable(String datasetSchemaId, boolean availableInPublic) { | ||
| schemasRepository.updateDatasetSchemaExportable(datasetSchemaId, availableInPublic); | ||
| } | ||
|
|
@@ -2152,7 +2171,7 @@ public void copyUniqueConstraintsCatalogue(List<String> originDatasetSchemaIds, | |
| */ | ||
| @Override | ||
| public SimpleDatasetSchemaVO getSimpleSchema(Long datasetId) throws EEAException { | ||
| String schemaId = getDatasetSchemaId(datasetId); | ||
| String schemaId = self.getDatasetSchemaId(datasetId); | ||
| if (schemaId != null) { | ||
| LOG.info("Getting schema from id {}", schemaId); | ||
| Optional<DesignDataset> designDataset = | ||
|
|
@@ -2249,7 +2268,7 @@ public Boolean checkClearAttachments(Long datasetId, String datasetSchemaId, | |
| */ | ||
| private void createNotEmptyRule(String tableSchemaId, Long datasetId) throws EEAException { | ||
| // retieve default level error if any | ||
| String datasetSchemaId = getDatasetSchemaId(datasetId); | ||
| String datasetSchemaId = self.getDatasetSchemaId(datasetId); | ||
| RulesSchema rulesSchema = rulesRepository.findByIdDatasetSchema(new ObjectId(datasetSchemaId)); | ||
|
|
||
| ErrorTypeEnum automaticQCDefaultLevelError = | ||
|
|
@@ -2570,7 +2589,7 @@ public void importSchemas(Long dataflowId, InputStream is, String fileName) | |
| */ | ||
| @Override | ||
| public List<TableSchemaIdNameVO> getTableSchemasIds(Long datasetId) throws EEAException { | ||
| String datasetschemaId = getDatasetSchemaId(datasetId); | ||
| String datasetschemaId = self.getDatasetSchemaId(datasetId); | ||
| DataSetSchema schema = schemasRepository.findByIdDataSetSchema(new ObjectId(datasetschemaId)); | ||
| List<TableSchemaIdNameVO> tableSchemasVOList = new ArrayList<>(); | ||
| for (TableSchema table : schema.getTableSchemas()) { | ||
|
|
@@ -2588,6 +2607,7 @@ public List<TableSchemaIdNameVO> getTableSchemasIds(Long datasetId) throws EEAEx | |
| * @param referenceDataset the reference dataset | ||
| */ | ||
| @Override | ||
| @Transactional | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @transactional here will only work if an exception is thrown from schemasRepository.updateReferenceDataset() on line 2606. updateTableSchema() on line 2614 can fail to update any of the tables and the transaction will still be considered valid, as the exception thrown by updateTableSchema() is swallowed. Let's discuss this with Fotis.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct. We have two problems here:
I see two options here:
|
||
| public void updateReferenceDataset(Long datasetId, String datasetSchemaId, | ||
| boolean referenceDataset) { | ||
|
|
||
|
|
@@ -2982,7 +3002,7 @@ private void updateImportFieldSchema(FieldSchemaVO fieldSchemaVO, List<FieldSche | |
| datasetService.deleteAttachmentByFieldSchemaId(datasetId, fieldSchemaVO.getId()); | ||
| } | ||
|
|
||
| DataType type = updateFieldSchema(datasetSchema.getIdDataSetSchema().toString(), | ||
| DataType type = self.updateFieldSchema(datasetSchema.getIdDataSetSchema().toString(), | ||
| fieldSchemaVO, datasetId, false); | ||
|
|
||
| // Create query view | ||
|
|
@@ -3371,10 +3391,10 @@ private void processToModifyTheFK(Map<String, String> dictionaryOriginTargetObje | |
| // update all the stuff | ||
| // related to the PK/FK | ||
| try { | ||
| String datasetSchemaId = getDatasetSchemaId(datasetId); | ||
| String datasetSchemaId = self.getDatasetSchemaId(datasetId); | ||
| updateForeignRelation(datasetId, fieldSchemaNoRulesMapper.entityToClass(field), | ||
| datasetSchemaId); | ||
| DataType type = updateFieldSchema(datasetSchemaId, | ||
| DataType type = self.updateFieldSchema(datasetSchemaId, | ||
| fieldSchemaNoRulesMapper.entityToClass(field), datasetId, true); | ||
| propagateRulesAfterUpdateSchema(datasetSchemaId, | ||
| fieldSchemaNoRulesMapper.entityToClass(field), type, datasetId); | ||
|
|
@@ -3633,7 +3653,7 @@ public String getFieldName(String datasetSchemaId, String tableSchemaId, List<St | |
| @Override | ||
| public String getFieldSchemaIdByDatasetIdTableNameAndFieldName(Long datasetId, String tableSchemaName, String fieldName){ | ||
| try { | ||
| String datasetSchemaId = getDatasetSchemaId(datasetId); | ||
| String datasetSchemaId = self.getDatasetSchemaId(datasetId); | ||
| DataSetSchemaVO datasetSchema = getDataSchemaById(datasetSchemaId); | ||
| if (datasetSchema != null) { | ||
| String finalTableSchemaName = tableSchemaName; | ||
|
|
@@ -3666,7 +3686,7 @@ public String getFieldSchemaIdByDatasetIdTableNameAndFieldName(Long datasetId, S | |
| */ | ||
| @Override | ||
| public void updateManuallyEditableByDatasetId(Long datasetId, Boolean manuallyEditable) throws EEAException { | ||
| String datasetSchemaId = getDatasetSchemaId(datasetId); | ||
| String datasetSchemaId = self.getDatasetSchemaId(datasetId); | ||
| List<TableSchemaIdNameVO> tableSchemaIds = getTableSchemasIds(datasetId); | ||
| for(TableSchemaIdNameVO tableSchemaIdNameVO: tableSchemaIds){ | ||
| TableSchemaVO tableSchemaVO = getTableSchemaVO(tableSchemaIdNameVO.getIdTableSchema(), datasetSchemaId); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since declaring self variables is not a thing we do in Java, please add a comment here to document this declaration, so it is obvious you are declaring a self variable to make Spring AOP work for self invocations of @transactional and @cachable, and @lazy to avoid circular dependancy error on startup. Intent comments are always welcome!