Skip to content
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

[DAT-17036] Fix incorrect error #538

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean supports(String url) {
return isMongodbConnection;
}

private static void showErrorMessageIfSomeRequiredDependenciesAreNotPresent(boolean isMongodbConnection) {
public static void showErrorMessageIfSomeRequiredDependenciesAreNotPresent(boolean isMongodbConnection) {
if (isMongodbConnection) {
final String errorMessagePrefix = "The required dependencies (JAR files) are not available on the classpath:";
String errorMessage = errorMessagePrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
* #L%
*/

import com.mongodb.MongoException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import liquibase.CatalogAndSchema;
import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import liquibase.executor.Executor;
Expand All @@ -36,9 +33,6 @@
import liquibase.nosql.database.AbstractNoSqlDatabase;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.bson.BsonDocument;
import org.bson.BsonInt64;
import org.bson.conversions.Bson;

import static liquibase.nosql.executor.NoSqlExecutor.EXECUTOR_NAME;

Expand Down Expand Up @@ -127,17 +121,7 @@ public Boolean getSupportsValidator() {

@Override
public void checkDatabaseConnection() throws DatabaseException {
DatabaseConnection connection = getConnection();
try {
if (connection instanceof MongoConnection) {
MongoClient mongoClient = ((MongoConnection) connection).getMongoClient();
Bson command = new BsonDocument("ping", new BsonInt64(1));
MongoDatabase adminDb = mongoClient.getDatabase(ADMIN_DATABASE_NAME);
adminDb.runCommand(command);
}
} catch (MongoException e) {
throw new DatabaseException(e);
}
MongoConnection.showErrorMessageIfSomeRequiredDependenciesAreNotPresent(true);
MongoLiquibaseDatabaseUtil.sendPingSignal(getConnection());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package liquibase.ext.mongodb.database;

import com.mongodb.MongoException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;
import org.bson.BsonDocument;
import org.bson.BsonInt64;
import org.bson.conversions.Bson;

import static liquibase.ext.mongodb.database.MongoLiquibaseDatabase.ADMIN_DATABASE_NAME;

public class MongoLiquibaseDatabaseUtil {
private MongoLiquibaseDatabaseUtil() {
}

public static void sendPingSignal(DatabaseConnection connection) throws DatabaseException {
try {
if (connection instanceof MongoConnection) {
MongoClient mongoClient = ((MongoConnection) connection).getMongoClient();
Bson command = new BsonDocument("ping", new BsonInt64(1));
MongoDatabase adminDb = mongoClient.getDatabase(ADMIN_DATABASE_NAME);
adminDb.runCommand(command);
}
} catch (MongoException e) {
throw new DatabaseException(e);
}
}
}
Loading