List of usage examples for com.mongodb AuthenticationMechanism getMechanismName
public String getMechanismName()
From source file:org.codinjutsu.tools.mongo.view.console.MongoConsoleRunner.java
License:Apache License
private static GeneralCommandLine buildCommandLine(String shellPath, ServerConfiguration serverConfiguration, MongoDatabase database) {// ww w.j a v a 2 s .co m GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(shellPath); commandLine.addParameter(MongoUtils.buildMongoUrl(serverConfiguration, database)); String shellWorkingDir = serverConfiguration.getShellWorkingDir(); if (StringUtils.isNotBlank(shellWorkingDir)) { commandLine.setWorkDirectory(shellWorkingDir); } String username = serverConfiguration.getUsername(); if (StringUtils.isNotBlank(username)) { commandLine.addParameter("--username"); commandLine.addParameter(username); } String password = serverConfiguration.getPassword(); if (StringUtils.isNotBlank(password)) { commandLine.addParameter("--password"); commandLine.addParameter(password); } String authenticationDatabase = serverConfiguration.getAuthenticationDatabase(); if (StringUtils.isNotBlank(authenticationDatabase)) { commandLine.addParameter("--authenticationDatabase"); commandLine.addParameter(authenticationDatabase); } AuthenticationMechanism authenticationMechanism = serverConfiguration.getAuthenticationMechanism(); if (authenticationMechanism != null) { commandLine.addParameter("--authenticationMechanism"); commandLine.addParameter(authenticationMechanism.getMechanismName()); } // ReadPreference readPreference = serverConfiguration.getReadPreference(); // if (readPreference != null) { // commandLine.addParameter("--readPreference"); // commandLine.addParameter(readPreference.getName()); // } String shellArgumentsLine = serverConfiguration.getShellArgumentsLine(); if (StringUtils.isNotBlank(shellArgumentsLine)) { commandLine.addParameters(shellArgumentsLine.split(" ")); } return commandLine; }
From source file:org.codinjutsu.tools.nosql.mongo.view.console.MongoConsoleRunner.java
License:Apache License
@Nullable @Override//from w w w . ja v a 2 s .c o m protected Process createProcess() throws ExecutionException { NoSqlConfiguration noSqlConfiguration = NoSqlConfiguration.getInstance(getProject()); String shellPath = noSqlConfiguration.getShellPath(DatabaseVendor.MONGO); final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(shellPath); commandLine.addParameter(MongoUtils.buildMongoUrl(serverConfiguration, database)); String shellWorkingDir = serverConfiguration.getShellWorkingDir(); if (StringUtils.isNotBlank(shellWorkingDir)) { commandLine.withWorkDirectory(shellWorkingDir); } AuthenticationSettings authenticationSettings = serverConfiguration.getAuthenticationSettings(); String username = authenticationSettings.getUsername(); if (StringUtils.isNotBlank(username)) { commandLine.addParameter("--username"); commandLine.addParameter(username); } String password = authenticationSettings.getPassword(); if (StringUtils.isNotBlank(password)) { commandLine.addParameter("--password"); commandLine.addParameter(password); } MongoExtraSettings mongoExtraSettings = new MongoExtraSettings(authenticationSettings.getExtras()); String authenticationDatabase = mongoExtraSettings.getAuthenticationDatabase(); if (StringUtils.isNotBlank(authenticationDatabase)) { commandLine.addParameter("--authenticationDatabase"); commandLine.addParameter(authenticationDatabase); } AuthenticationMechanism authenticationMecanism = mongoExtraSettings.getAuthenticationMechanism(); if (authenticationMecanism != null) { commandLine.addParameter("--authenticationMecanism"); commandLine.addParameter(authenticationMecanism.getMechanismName()); } String shellArgumentsLine = serverConfiguration.getShellArgumentsLine(); if (StringUtils.isNotBlank(shellArgumentsLine)) { commandLine.addParameters(shellArgumentsLine.split(" ")); } return commandLine.createProcess(); }