Skip to content

Commit

Permalink
Minor polish
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Sep 3, 2024
1 parent 0c865bd commit 6b0812e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@
import com.google.errorprone.refaster.annotation.BeforeTemplate;
import com.mongodb.MongoClientURI;
import org.openrewrite.java.template.RecipeDescriptor;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

@RecipeDescriptor(
name = "Refactor `SimpleMongoDbFactory(new MongoClientURI(String))` to `SimpleMongoClientDbFactory(String)`",
description = "As part of spring-data-mongodb 2.3 migration the deprecated usage of `SimpleMongoDbFactory(new MongoClientURI(String))` has to be refactored to use `SimpleMongoClientDbFactory`"
)
name = "Use `new SimpleMongoClientDbFactory(String)`",
description = "Replace usage of deprecated `new SimpleMongoDbFactory(new MongoClientURI(String))` with `new SimpleMongoClientDbFactory(String)`.")
@SuppressWarnings("deprecation")
public class RefactorSimpleMongoDbFactory {

@BeforeTemplate
public SimpleMongoDbFactory before(String uri) {
public MongoDbFactory before(String uri) {
return new SimpleMongoDbFactory(new MongoClientURI(uri));
}

@AfterTemplate
public SimpleMongoClientDbFactory after(String uri) {
public MongoDbFactory after(String uri) {
return new SimpleMongoClientDbFactory(uri);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/spring-data-23.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.data.UpgradeSpringData_2_3
displayName: Migrate to Spring Data 2.3 local
displayName: Migrate to Spring Data 2.3
description: Migrate applications to the latest Spring Data 2.3 release.
recipeList:
- org.openrewrite.java.spring.data.MigrateJpaSort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void defaults(RecipeSpec spec) {

@DocumentExample
@Test
@SuppressWarnings("deprecation")
void constructorWithAttribute() {
//language=java
rewriteRun(
Expand All @@ -43,11 +44,8 @@ void constructorWithAttribute() {
import com.mongodb.MongoClientURI;
class Test {
MongoDbFactory factory;
SimpleMongoDbFactory factory2;
void setupUri(String uri) {
factory2 = new SimpleMongoDbFactory(new MongoClientURI(uri));
MongoDbFactory setupUri(String uri) {
return new SimpleMongoDbFactory(new MongoClientURI(uri));
}
}
""",
Expand All @@ -56,11 +54,8 @@ void setupUri(String uri) {
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
class Test {
MongoDatabaseFactory factory;
SimpleMongoClientDatabaseFactory factory2;
void setupUri(String uri) {
factory2 = new SimpleMongoClientDatabaseFactory(uri);
MongoDatabaseFactory setupUri(String uri) {
return new SimpleMongoClientDatabaseFactory(uri);
}
}
"""
Expand Down

0 comments on commit 6b0812e

Please sign in to comment.