Skip to content

chore: refactor datasource storage to use custom repo method#38143

Merged
AnaghHegde merged 4 commits intoreleasefrom
chore/refactor-datasource-storage-crud-repository
Dec 18, 2024
Merged

chore: refactor datasource storage to use custom repo method#38143
AnaghHegde merged 4 commits intoreleasefrom
chore/refactor-datasource-storage-crud-repository

Conversation

@AnaghHegde
Copy link
Contributor

@AnaghHegde AnaghHegde commented Dec 13, 2024

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 DatasourceStorageRepository from the default CrudRepository.

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12388971717
Commit: 977d50e
Cypress dashboard.
Tags: @tag.ImportExport
Spec:


Wed, 18 Dec 2024 09:08:53 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added methods to retrieve DatasourceStorage by datasourceId and environmentId.
    • Enhanced functionality for fetching DatasourceStorage based on datasourceId.
  • Bug Fixes

    • Removed the ability to find a datasource by both its ID and environment ID in the repository interface.
  • Documentation

    • Updated repository annotations to reflect new functionalities and integrations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in this pull request involve modifications to the CustomDatasourceStorageRepositoryCE interface and its implementation, CustomDatasourceStorageRepositoryCEImpl. Two new methods are introduced for retrieving DatasourceStorage objects based on datasourceId and environmentId. Additionally, the DatasourceStorageRepositoryCE interface is updated to extend the CustomDatasourceStorageRepository, while one of its previous methods is removed.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCE.java - Added method: Mono<DatasourceStorage> findByDatasourceIdAndEnvironmentId(String, String)
- Added method: Flux<DatasourceStorage> findByDatasourceId(String)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCEImpl.java - Added method: Mono<DatasourceStorage> findByDatasourceIdAndEnvironmentId(String, String)
- Updated method: Flux<DatasourceStorage> findByDatasourceId(String)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageRepositoryCE.java - Updated interface to extend CustomDatasourceStorageRepository
- Removed method: Mono<DatasourceStorage> findByDatasourceIdAndEnvironmentId(String, String)

Possibly related PRs

  • chore: refactor crud repository methods #38144: This PR adds a method findByDatasourceIdAndEnvironmentId to the CustomDatasourceStorageStructureRepositoryCE interface, which is directly related to the methods added in the main PR for CustomDatasourceStorageRepositoryCE, enhancing the functionality for retrieving DatasourceStorage objects based on identifiers.

Suggested reviewers

  • abhvsn
  • sharat87

🌟 In the realm of code, new methods arise,
To fetch data swiftly, a clever surprise!
With datasourceId and env in hand,
Our queries now flourish, just as we planned.
So here's to the changes, both bold and bright,
In the world of Appsmith, we soar to new heights! 🚀


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff19aa2 and 977d50e.

📒 Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageRepositoryCE.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageRepositoryCE.java
🔇 Additional comments (4)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCE.java (2)

5-7: LGTM! Appropriate reactive imports.

The imports for Mono and Flux are correctly added for reactive programming support.


8-12: LGTM! Well-structured interface.

The interface is well-designed with:

  • Clear method signatures
  • Appropriate return types (Mono/Flux) for reactive operations
  • Meaningful parameter names
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCEImpl.java (2)

13-18: Add parameter validation and error handling.


21-25: 🛠️ Refactor suggestion

Add parameter validation and error handling for findByDatasourceId.

Similar to the other method, this one needs proper validation and error handling.

@Override
public Flux<DatasourceStorage> findByDatasourceId(String datasourceId) {
+    if (datasourceId == null) {
+        return Flux.error(new IllegalArgumentException("datasourceId cannot be null"));
+    }
    final BridgeQuery<DatasourceStorage> q =
            Bridge.<DatasourceStorage>equal(DatasourceStorage.Fields.datasourceId, datasourceId);
-    return queryBuilder().criteria(q).all();
+    return queryBuilder().criteria(q).all()
+        .switchIfEmpty(Flux.empty());
}

Likely invalid or redundant comment.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@AnaghHegde AnaghHegde requested review from abhvsn and removed request for nidhi-nair and sondermanish December 13, 2024 05:44
@AnaghHegde AnaghHegde added the ok-to-test Required label for CI label Dec 13, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 13, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6eb44a1 and 04d8994.

📒 Files selected for processing (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageRepositoryCE.java (1 hunks)
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageRepositoryCE.java (1)

7-9: LGTM! Clean interface definition.

The interface follows Spring Data repository patterns and reactive programming principles.

app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageRepositoryCE.java (1)

9-11: Verify Spring repository configuration.

The repository structure looks correct, but let's verify the bean configuration.

✅ Verification successful

Let me verify the Spring repository configuration by checking for any component scanning issues.


Let me check the component scanning configuration in ServerApplication.java to verify the repository setup.


Repository configuration is correctly set up

The Spring configuration is properly structured with:

  • Component scanning enabled for "com.appsmith" package
  • Clear repository hierarchy (DatasourceStorageRepository -> DatasourceStorageRepositoryCE)
  • Proper implementation classes present (CustomDatasourceStorageRepositoryImpl)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any conflicting repository definitions
rg -l "interface.*DatasourceStorageRepository.*extends" | while read -r file; do
  echo "=== $file ==="
  rg "interface.*DatasourceStorageRepository.*extends" "$file"
done

Length of output: 1691


Script:

#!/bin/bash
# Check for Spring component scanning configuration
rg -l "ComponentScan|EnableJpaRepositories" app/server/appsmith-server/src/main/java/

Length of output: 171


Script:

#!/bin/bash
# Check repository implementation
rg -l "class.*DatasourceStorageRepository.*implements" app/server/appsmith-server/src/main/java/

Length of output: 98


Script:

#!/bin/bash
# Check for any repository bean configuration in XML or Java config
fd -e xml -e java | xargs rg "bean.*[\"']datasourceStorageRepository[\"']"

Length of output: 80


Script:

#!/bin/bash
# Check ServerApplication.java for repository configuration
rg -A 5 "ComponentScan|EnableJpaRepositories" app/server/appsmith-server/src/main/java/com/appsmith/server/ServerApplication.java

Length of output: 430


Script:

#!/bin/bash
# Check for repository implementation in CustomDatasourceStorageRepositoryImpl
fd -e java | rg "CustomDatasourceStorageRepository.*Impl"

Length of output: 298

Copy link
Contributor

@abhvsn abhvsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment.

@AnaghHegde AnaghHegde requested a review from abhvsn December 13, 2024 09:18
@AnaghHegde AnaghHegde enabled auto-merge (squash) December 14, 2024 11:17
@AnaghHegde AnaghHegde added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 18, 2024
@AnaghHegde AnaghHegde merged commit 836b544 into release Dec 18, 2024
@AnaghHegde AnaghHegde deleted the chore/refactor-datasource-storage-crud-repository branch December 18, 2024 09:09
NandanAnantharamu pushed a commit that referenced this pull request Dec 27, 2024
## 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 DatasourceStorageRepository from the default
CrudRepository.


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12313769237>
> Commit: 977d50e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12313769237&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: @tag.Datasource
> Spec: 
> It seems like **no tests ran** 😔. We are not able to recognize it,
please check <a
href="https://github.com/appsmithorg/appsmith/actions/runs/12313769237"
target="_blank">workflow here</a>.
> <hr>Sat, 14 Dec 2024 11:00:53 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**
- Added methods to retrieve `DatasourceStorage` by `datasourceId` and
`environmentId`.
- Enhanced functionality for fetching `DatasourceStorage` based on
`datasourceId`.

- **Bug Fixes**
- Removed the ability to find a datasource by both its ID and
environment ID in the repository interface.

- **Documentation**
- Updated repository annotations to reflect new functionalities and
integrations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
…horg#38143)

## 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 DatasourceStorageRepository from the default
CrudRepository.


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12313769237>
> Commit: 977d50e
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12313769237&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: @tag.Datasource
> Spec: 
> It seems like **no tests ran** 😔. We are not able to recognize it,
please check <a
href="https://github.com/appsmithorg/appsmith/actions/runs/12313769237"
target="_blank">workflow here</a>.
> <hr>Sat, 14 Dec 2024 11:00:53 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**
- Added methods to retrieve `DatasourceStorage` by `datasourceId` and
`environmentId`.
- Enhanced functionality for fetching `DatasourceStorage` based on
`datasourceId`.

- **Bug Fixes**
- Removed the ability to find a datasource by both its ID and
environment ID in the repository interface.

- **Documentation**
- Updated repository annotations to reflect new functionalities and
integrations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants