Operations: How to Add Connection String
You can add a connection string by using PutConnectionStringOperation.
Syntax
public PutConnectionStringOperation(T connectionString)
Parameters | ||
---|---|---|
connectionString | T |
Connection string to create: RavenConnectionString or SqlConnectionString |
RavenConnectionString
public class RavenConnectionString extends ConnectionString {
private String database; // target database name
private String[] topologyDiscoveryUrls; // list of server urls
public ConnectionStringType getType() {
return ConnectionStringType.RAVEN;
}
// getters and setters
}
SqlConnectionString
public class SqlConnectionString extends ConnectionString {
private String connectionString;
private String factoryName;
public ConnectionStringType getType() {
return ConnectionStringType.SQL;
}
// getters and setters
}
ConnectionString
public class ConnectionString {
private String name; // name of connection string
// getters and setters
}
Example - Add Raven Connection String
RavenConnectionString connectionString = new RavenConnectionString();
connectionString.setName("raven2");
connectionString.setDatabase("Northwind2");
connectionString.setTopologyDiscoveryUrls(new String[]{"http://rvn2:8080"});
PutConnectionStringOperation<RavenConnectionString> operation =
new PutConnectionStringOperation<>(connectionString);
PutConnectionStringResult connectionStringResult =
store.maintenance().send(operation);
Example - Add Sql Connection String
SqlConnectionString connectionString = new SqlConnectionString();
connectionString.setName("local_mysql");
connectionString.setFactoryName("MySql.Data.MySqlClient");
connectionString.setConnectionString("host=127.0.0.1;user=root;database=Northwind");
PutConnectionStringOperation<SqlConnectionString> operation
= new PutConnectionStringOperation<>(connectionString);
PutConnectionStringResult connectionStringResult = store.maintenance().send(operation);