Skip to content

Commit

Permalink
Remove unwanted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed Jan 7, 2025
1 parent 5c7582e commit 7802f77
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 68 deletions.
5 changes: 4 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ org.eclipse.core.runtime_3.9.0.v20130326-1255.jar
com.google.guava.failureaccess_1.0.2.jar bundle apache2
asn-one_0.6.0.wso2v1.jar bundle apache2
poi_5.3.0.wso2v1.jar bundle apache2
org.mongodb.mongo-java-driver_3.5.0.jar bundle apache2
org.wso2.micro.integrator.dataservices.core_4.3.0.jar bundle apache2
org.mongodb.mongodb-driver-sync_4.9.1.jar bundle apache2
org.mongodb.mongodb-driver-core_4.9.1.jar bundle apache2
org.mongodb.bson_4.9.1.jar bundle apache2
org.sat4j.pb_2.3.5.v201308161310.jar bundle epl1 + lgpl2
neethi_2.0.4.wso2v5.jar bundle apache2
org.wso2.carbon.crypto.api_1.1.3.jar bundle apache2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ private MongoDB() {
public static final String SSL_ENABLED = "mongoDB_ssl_enabled";
public static final String AUTH_SOURCE = "mongoDB_auth_source";
public static final String CONNECTIONS_PER_HOST = "mongoDB_connectionsPerHost";
public static final String THREADS_ALLOWED_TO_BLOCK_CONN_MULTIPLIER = "mongoDB_threadsAllowedToBlockForConnectionMultiplier";
public static final String RESULT_COLUMN_NAME = "Document";

public static class MongoOperationLabels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@
<groupId>de.undercouch</groupId>
<artifactId>bson4jackson</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.mongodb</groupId>-->
<!-- <artifactId>mongo-java-driver</artifactId>-->
<!-- <version>3.12.7</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
*/
package org.wso2.micro.integrator.dataservices.core.description.config;

//import com.mongodb.Mongo;
import com.mongodb.ReadPreference;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoClient;
//import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
Expand All @@ -30,7 +28,6 @@
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//import org.jongo.Jongo;
import org.wso2.micro.integrator.dataservices.common.DBConstants;
import org.wso2.micro.integrator.dataservices.core.DBUtils;import org.wso2.micro.integrator.dataservices.core.DataServiceFault;import org.wso2.micro.integrator.dataservices.core.engine.DataService;import org.wso2.micro.integrator.dataservices.core.odata.MongoDataHandler;import org.wso2.micro.integrator.dataservices.core.odata.ODataDataHandler;

Expand All @@ -48,13 +45,10 @@ public class MongoConfig extends Config {
private static final Log log = LogFactory.getLog(
MongoConfig.class);

private MongoClient mongoClient;
private final MongoClient mongoClient;

private String [] servers;

private MongoClientSettings mongoClientSettings;
private MongoDatabase mongoDatabase;
// private Jongo jongo;
private final MongoClientSettings mongoClientSettings;
private final MongoDatabase mongoDatabase;

public MongoConfig(DataService dataService, String configId, Map<String, String> properties, boolean odataEnable)
throws DataServiceFault {
Expand All @@ -63,27 +57,20 @@ public MongoConfig(DataService dataService, String configId, Map<String, String>
if (DBUtils.isEmptyString(serversParam)) {
throw new DataServiceFault("The data source param '" + DBConstants.MongoDB.SERVERS + "' is required");
}
this.servers = serversParam.split(",");
String[] servers = serversParam.split(",");
String database = properties.get(DBConstants.MongoDB.DATABASE);
if (DBUtils.isEmptyString(database)) {
throw new DataServiceFault("The data source param '" + DBConstants.MongoDB.DATABASE + "' is required");
}
try {
String writeConcern = properties.get(DBConstants.MongoDB.WRITE_CONCERN);
String readPref = properties.get(DBConstants.MongoDB.READ_PREFERENCE);
List<ServerAddress> serverAddresses = createServerAddresses(this.servers);
List<ServerAddress> serverAddresses = createServerAddresses(servers);
MongoCredential mongoCredentials = createCredential(properties);
this.mongoClientSettings = extractMongoOptions(properties, writeConcern, readPref, serverAddresses,
mongoCredentials);
this.mongoClient = createNewMongo(this.mongoClientSettings);
// if (!DBUtils.isEmptyString(writeConcern)) {
// this.getMongoClient().setWriteConcern(WriteConcern.valueOf(writeConcern));
// }
// if (!DBUtils.isEmptyString(readPref)) {
// this.getMongoClient().setReadPreference(ReadPreference.valueOf(readPref));
// }
this.mongoDatabase = this.getMongoClient().getDatabase(database);
// this.jongo = new Jongo(this.getMongoClient().getDB(database));
} catch (Exception e) {
throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage());
}
Expand All @@ -93,13 +80,6 @@ public MongoConfig(DataService dataService, String configId, Map<String, String>
public MongoClient createNewMongo(MongoClientSettings mongoClientSettings) throws DataServiceFault {
try {
return MongoClients.create(mongoClientSettings);
// MongoCredential credential = createCredential(properties);
// if (credential != null) {
// return new MongoClient(this.createServerAddresses(this.getServers()),
// Collections.singletonList(credential), getMongoClientSettings());
// } else {
// return new MongoClient(this.createServerAddresses(this.getServers()), getMongoClientSettings());
// }
} catch (Exception e) {
throw new DataServiceFault(e);
}
Expand All @@ -122,11 +102,9 @@ public void close() {
/* nothing to close */
}

// TODO: Check this.
@Override
public ODataDataHandler createODataHandler() {
return new MongoDataHandler(getConfigId(), this.mongoDatabase);
// return new MongoDataHandler(getConfigId(), getJongo());
}

private MongoClientSettings extractMongoOptions(Map<String, String> properties, String writeConcern,
Expand All @@ -135,40 +113,28 @@ private MongoClientSettings extractMongoOptions(Map<String, String> properties,
String connectionsPerHost = properties.get(DBConstants.MongoDB.CONNECTIONS_PER_HOST);
if (!DBUtils.isEmptyString(connectionsPerHost)) {
settingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxSize(Integer.parseInt(connectionsPerHost)));
// builder.connectionsPerHost(Integer.parseInt(connectionsPerHost));
}
String maxWaitTime = properties.get(DBConstants.MongoDB.MAX_WAIT_TIME);
if (!DBUtils.isEmptyString(maxWaitTime)) {
settingsBuilder.applyToConnectionPoolSettings(builder -> builder.maxWaitTime(Integer.parseInt(maxWaitTime),
TimeUnit.MILLISECONDS));
// settingsBuilder.maxWaitTime(Integer.parseInt(maxWaitTime));
}
String connectTimeout = properties.get(DBConstants.MongoDB.CONNECT_TIMEOUT);
if (!DBUtils.isEmptyString(connectTimeout)) {
settingsBuilder.applyToSocketSettings(builder -> builder.connectTimeout(Integer.parseInt(connectTimeout),
TimeUnit.MILLISECONDS));
// settingsBuilder.connectTimeout(Integer.parseInt(connectTimeout));
}
String socketTimeout = properties.get(DBConstants.MongoDB.SOCKET_TIMEOUT);
if (!DBUtils.isEmptyString(socketTimeout)) {
settingsBuilder.applyToSocketSettings(builder -> builder.connectTimeout(Integer.parseInt(socketTimeout),
settingsBuilder.applyToSocketSettings(builder -> builder.readTimeout(Integer.parseInt(socketTimeout),
TimeUnit.MILLISECONDS));
// settingsBuilder.socketTimeout(Integer.parseInt(socketTimeout));
}
String threadsAllowedToBlockForConnectionMultiplier = properties.get(
DBConstants.MongoDB.THREADS_ALLOWED_TO_BLOCK_CONN_MULTIPLIER);
if (!DBUtils.isEmptyString(threadsAllowedToBlockForConnectionMultiplier)) {
// settingsBuilder.threadsAllowedToBlockForConnectionMultiplier(
// Integer.parseInt(threadsAllowedToBlockForConnectionMultiplier));
}

String sslEnabled = (properties.get(DBConstants.MongoDB.SSL_ENABLED));
if (Boolean.parseBoolean(sslEnabled)) {
settingsBuilder.applyToSslSettings(builder -> builder.enabled(true));
// settingsBuilder.sslEnabled(true);
}
if (!DBUtils.isEmptyString(writeConcern)) {
settingsBuilder.writeConcern(new WriteConcern(writeConcern));
settingsBuilder.writeConcern(WriteConcern.valueOf(writeConcern.toUpperCase()));
}
if (!DBUtils.isEmptyString(readPref)) {
settingsBuilder.readPreference(ReadPreference.valueOf(readPref));
Expand Down Expand Up @@ -218,11 +184,6 @@ private MongoCredential createCredential(Map<String, String> properties) throws
case DBConstants.MongoDB.MongoAuthenticationTypes.SCRAM_SHA_1:
credential = MongoCredential.createScramSha1Credential(username, authSource, password.toCharArray());
break;

// TODO: This has been removed from 4.x onwards. Discuss this.
// case DBConstants.MongoDB.MongoAuthenticationTypes.MONGODB_CR:
// credential = MongoCredential.createMongoCRCredential(username, authSource, password.toCharArray());
// break;
case DBConstants.MongoDB.MongoAuthenticationTypes.GSSAPI:
credential = MongoCredential.createGSSAPICredential(username);
break;
Expand All @@ -238,18 +199,6 @@ private MongoCredential createCredential(Map<String, String> properties) throws
}
}

public String[] getServers() {
return servers;
}

public MongoClientSettings getMongoClientSettings() {
return mongoClientSettings;
}

// public Jongo getJongo() {
// return jongo;
// }

public MongoDatabase getMongoDatabase() {
return mongoDatabase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public class MongoDataHandler implements ODataDataHandler {
/**
* DocumentId/ObjectId s of the Collections
*/
private Map<String, List<String>> primaryKeys;
private final Map<String, List<String>> primaryKeys;

/**
* List of Collections in the Database.
*/
private List<String> tableList;
private final List<String> tableList;

/**
* Metadata of the Collections
Expand Down

0 comments on commit 7802f77

Please sign in to comment.