Skip to content

Commit

Permalink
chore: refactor crud repository methods (appsmithorg#38144)
Browse files Browse the repository at this point in the history
## Description
As part of transaction support in PG, we are moving from using the jpa
methods for database operations. This PR is refactoring the code to use
custom repository class for DatasourceStorageStructureRepository from
the default CrudRepository.

## Automation

/ok-to-test tags="@tag.Datasource"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12310505479>
> Commit: f226809
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12310505479&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Fri, 13 Dec 2024 07:34:38 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a method to retrieve `DatasourceStorageStructure` based on
datasource and environment identifiers.
  
- **Bug Fixes**
- Simplified the structure of the
`DatasourceStorageStructureRepositoryCE` interface by removing an
outdated method.

- **Documentation**
- Added `@Repository` annotation to the
`DatasourceStorageStructureRepositoryCE` interface to indicate its role
as a Spring Data repository.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
AnaghHegde authored Dec 13, 2024
1 parent 1ff19e7 commit c5a2670
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.appsmith.server.repositories.ce;

import com.appsmith.external.models.DatasourceStorageStructure;
import com.appsmith.external.models.DatasourceStructure;
import reactor.core.publisher.Mono;

public interface CustomDatasourceStorageStructureRepositoryCE {

Mono<Integer> updateStructure(String datasourceId, String environmentId, DatasourceStructure structure);

Mono<DatasourceStorageStructure> findByDatasourceIdAndEnvironmentId(String datasourceId, String environmentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.appsmith.external.models.DatasourceStorageStructure;
import com.appsmith.external.models.DatasourceStructure;
import com.appsmith.server.helpers.ce.bridge.Bridge;
import com.appsmith.server.helpers.ce.bridge.BridgeQuery;
import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
Expand All @@ -19,4 +20,13 @@ public Mono<Integer> updateStructure(String datasourceId, String environmentId,
.equal(DatasourceStorageStructure.Fields.environmentId, environmentId))
.updateFirst(Bridge.update().set(DatasourceStorageStructure.Fields.structure, structure));
}

@Override
public Mono<DatasourceStorageStructure> findByDatasourceIdAndEnvironmentId(
String datasourceId, String environmentId) {
final BridgeQuery<DatasourceStorageStructure> q = Bridge.<DatasourceStorageStructure>equal(
DatasourceStorageStructure.Fields.datasourceId, datasourceId)
.equal(DatasourceStorageStructure.Fields.environmentId, environmentId);
return queryBuilder().criteria(q).one();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.appsmith.external.models.DatasourceStorageStructure;
import com.appsmith.server.repositories.BaseRepository;
import com.appsmith.server.repositories.CustomDatasourceStorageStructureRepository;
import reactor.core.publisher.Mono;
import org.springframework.stereotype.Repository;

@Repository
public interface DatasourceStorageStructureRepositoryCE
extends BaseRepository<DatasourceStorageStructure, String>, CustomDatasourceStorageStructureRepository {

Mono<DatasourceStorageStructure> findByDatasourceIdAndEnvironmentId(String datasourceId, String environmentId);
}
extends BaseRepository<DatasourceStorageStructure, String>, CustomDatasourceStorageStructureRepository {}

0 comments on commit c5a2670

Please sign in to comment.