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

Add port parameter to --wp #47

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.ipr
*.iws
out
/bin/
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public static BasicDataSource createDataSource(DatabaseLoginCredentials credenti
switch (credentials.getDbType()) {
case POSTGRESQL:
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://" + credentials.getHost() + "/" + credentials.getDatabase()
dataSource.setUrl("jdbc:postgresql://" + credentials.getHost() + ":"
+ credentials.getPort() + "/" + credentials.getDatabase()
/*+ "?loglevel=2"*/);
break;
case MYSQL:
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://" + credentials.getHost() + "/" + credentials.getDatabase());
dataSource.setUrl("jdbc:mysql://" + credentials.getHost() + ":"
+ credentials.getPort() + "/" + credentials.getDatabase());
break;
default:
throw new OsmosisRuntimeException("Unknown database type " + credentials.getDbType() + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ private Connection getPostgresConnection() {
LOG.finer("Creating a new database connection.");

newConnection = DriverManager.getConnection(
"jdbc:postgresql://" + loginCredentials.getHost() + "/"
"jdbc:postgresql://" + loginCredentials.getHost() + ":"
+ loginCredentials.getPort() + "/"
+ loginCredentials.getDatabase(), // + "?logLevel=2"
loginCredentials.getUser(),
loginCredentials.getPassword()
Expand All @@ -126,8 +127,10 @@ private Connection getMysqlConnection() {
try {
String url;

url = "jdbc:mysql://" + loginCredentials.getHost() + "/" + loginCredentials.getDatabase() + "?user="
+ loginCredentials.getUser() + "&password=" + loginCredentials.getPassword();
url = "jdbc:mysql://" + loginCredentials.getHost() + ":" + loginCredentials.getPort()
+ "/" + loginCredentials.getDatabase()
+ "?user=" + loginCredentials.getUser()
+ "&password=" + loginCredentials.getPassword();

if (loginCredentials.getForceUtf8()) {
url += "&useUnicode=true&characterEncoding=UTF-8";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public DatabaseContext createDatabaseContext() {
DatabaseLoginCredentials credentials;

credentials = new DatabaseLoginCredentials(DatabaseConstants.TASK_DEFAULT_HOST,
DatabaseConstants.TASK_DEFAULT_PORT,
DatabaseConstants.TASK_DEFAULT_DATABASE, DatabaseConstants.TASK_DEFAULT_USER,
DatabaseConstants.TASK_DEFAULT_PASSWORD, DatabaseConstants.TASK_DEFAULT_FORCE_UTF8,
DatabaseConstants.TASK_DEFAULT_PROFILE_SQL, DatabaseConstants.TASK_DEFAULT_DB_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* The recognised properties are:
* <ul>
* <li>host</li>
* <li>port</li>
* <li>database</li>
* <li>user</li>
* <li>password</li>
Expand All @@ -25,6 +26,7 @@
public class AuthenticationPropertiesLoader {

private static final String KEY_HOST = "host";
private static final String KEY_PORT = "port";
private static final String KEY_DATABASE = "database";
private static final String KEY_USER = "user";
private static final String KEY_PASSWORD = "password";
Expand Down Expand Up @@ -69,6 +71,9 @@ public void updateLoginCredentials(DatabaseLoginCredentials loginCredentials) {
if (properties.containsKey(KEY_HOST)) {
loginCredentials.setHost(properties.getProperty(KEY_HOST));
}
if (properties.containsKey(KEY_PORT)) {
loginCredentials.setPort(properties.getProperty(KEY_PORT));
}
if (properties.containsKey(KEY_DATABASE)) {
loginCredentials.setDatabase(properties.getProperty(KEY_DATABASE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public final class DatabaseConstants {
*/
public static final String TASK_ARG_HOST = "host";

/**
* The task argument for specifying the port for a database connection.
*/
public static final String TASK_ARG_PORT = "port";

/**
* The task argument for specifying the database instance for a database connection.
*/
Expand Down Expand Up @@ -70,6 +75,11 @@ public final class DatabaseConstants {
*/
public static final String TASK_DEFAULT_HOST = "localhost";

/**
* The default port for a database connection.
*/
public static final String TASK_DEFAULT_PORT = "5432";

/**
* The default database for a database connection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class DatabaseLoginCredentials {

private String datasourceJndiLocation;
private String host;
private String port;
private String database;
private String user;
private String password;
Expand All @@ -35,6 +36,8 @@ public DatabaseLoginCredentials(String datasourceJndiLocation) {
*
* @param host
* The server hosting the database.
* @param port
* The port the database is running on. Defaults to 5432.
* @param database
* The database instance.
* @param user
Expand All @@ -50,9 +53,10 @@ public DatabaseLoginCredentials(String datasourceJndiLocation) {
* @param dbType
* The database type.
*/
public DatabaseLoginCredentials(String host, String database, String user, String password, boolean forceUtf8,
public DatabaseLoginCredentials(String host, String port, String database, String user, String password, boolean forceUtf8,
boolean profileSql, DatabaseType dbType) {
this.host = host;
this.port = port;
this.database = database;
this.user = user;
this.password = password;
Expand All @@ -61,7 +65,7 @@ public DatabaseLoginCredentials(String host, String database, String user, Strin
this.dbType = dbType;
this.postgresSchema = "";
}


/**
* Gets the location of the datasource in JNDI. If null, new connections
Expand All @@ -82,7 +86,8 @@ public String getDatasourceJndiLocation() {
public String getHost() {
return host;
}



/**
* Updates the host.
*
Expand All @@ -92,6 +97,24 @@ public void setHost(String host) {
this.host = host;
}

/**
* Returns the port.
*
* @return The port.
*/
public String getPort() {
return port;
}

/**
* Updates the port.
*
* @param port The new port.
*/
public void setPort(String port) {
this.port = port;
}

/**
* Returns the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected DatabaseLoginCredentials getDatabaseLoginCredentials(TaskConfiguration

// Create a new credential object with default values.
loginCredentials = new DatabaseLoginCredentials(DatabaseConstants.TASK_DEFAULT_HOST,
DatabaseConstants.TASK_DEFAULT_PORT,
DatabaseConstants.TASK_DEFAULT_DATABASE, DatabaseConstants.TASK_DEFAULT_USER,
DatabaseConstants.TASK_DEFAULT_PASSWORD, DatabaseConstants.TASK_DEFAULT_FORCE_UTF8,
DatabaseConstants.TASK_DEFAULT_PROFILE_SQL, DatabaseConstants.TASK_DEFAULT_DB_TYPE);
Expand All @@ -43,6 +44,8 @@ protected DatabaseLoginCredentials getDatabaseLoginCredentials(TaskConfiguration
// command line.
loginCredentials.setHost(getStringArgument(taskConfig, DatabaseConstants.TASK_ARG_HOST, loginCredentials
.getHost()));
loginCredentials.setPort(getStringArgument(taskConfig, DatabaseConstants.TASK_ARG_PORT, loginCredentials
.getPort()));
loginCredentials.setDatabase(getStringArgument(taskConfig, DatabaseConstants.TASK_ARG_DATABASE,
loginCredentials.getDatabase()));
loginCredentials.setUser(getStringArgument(taskConfig, DatabaseConstants.TASK_ARG_USER, loginCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class Configuration {

private static final String KEY_HOST = "host";
private static final String KEY_PORT = "port";
private static final String KEY_DATABASE = "database";
private static final String KEY_USER = "user";
private static final String KEY_PASSWORD = "password";
Expand Down Expand Up @@ -82,6 +83,15 @@ public String getHost() {
return getProperty(KEY_HOST);
}

/**
* Returns the database port.
*
* @return The database port.
*/
public String getPort() {
return getProperty(KEY_PORT);
}


/**
* Returns the database instance.
Expand Down Expand Up @@ -201,7 +211,7 @@ public boolean getAllowIncorrectSchemaVersion() {
* @return The database login credentials.
*/
public DatabaseLoginCredentials getDatabaseLoginCredentials() {
return new DatabaseLoginCredentials(getHost(), getDatabase(), getUser(), getPassword(), false, false,
return new DatabaseLoginCredentials(getHost(), getPort(), getDatabase(), getUser(), getPassword(), false, false,
getDbType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private void infoCommand() {

System.out.println("Configuration");
System.out.println("\thost: " + configuration.getHost());
System.out.println("\tport: " + configuration.getPort());
System.out.println("\tdatabase: " + configuration.getDatabase());
System.out.println("\tuser: " + configuration.getUser());
System.out.println("\tpassword: " + configuration.getPassword());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# The database host system.
host=localhost
# The database port.
port=5432
# The database instance.
database=osm
# The database user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DatabaseContext createDatabaseContext() {
AuthenticationPropertiesLoader credentialsLoader;
DatabaseLoginCredentials credentials;

credentials = new DatabaseLoginCredentials(DatabaseConstants.TASK_DEFAULT_HOST,
credentials = new DatabaseLoginCredentials(DatabaseConstants.TASK_DEFAULT_HOST, DatabaseConstants.TASK_DEFAULT_PORT,
DatabaseConstants.TASK_DEFAULT_DATABASE, DatabaseConstants.TASK_DEFAULT_USER,
DatabaseConstants.TASK_DEFAULT_PASSWORD, DatabaseConstants.TASK_DEFAULT_FORCE_UTF8,
DatabaseConstants.TASK_DEFAULT_PROFILE_SQL, DatabaseConstants.TASK_DEFAULT_DB_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DatabaseContext(DatabaseLoginCredentials loginCredentials) {
private Connection getConnectionFromDriverManager() {
try {
return DriverManager.getConnection(
"jdbc:postgresql://" + loginCredentials.getHost() + "/"
"jdbc:postgresql://" + loginCredentials.getHost() + ":" + loginCredentials.getPort() + "/"
+ loginCredentials.getDatabase(),
// + "?logLevel=2"
loginCredentials.getUser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void createDataSource() {
localDataSource = new BasicDataSource();

localDataSource.setDriverClassName("org.postgresql.Driver");
localDataSource.setUrl("jdbc:postgresql://" + credentials.getHost() + "/" + credentials.getDatabase()
localDataSource.setUrl("jdbc:postgresql://" + credentials.getHost() + ":" + credentials.getPort() + "/" + credentials.getDatabase()
/*+ "?loglevel=2"*/);

localDataSource.setUsername(credentials.getUser());
Expand Down Expand Up @@ -87,7 +87,7 @@ private Connection createConnectionFromDriverManager() {
}

return DriverManager.getConnection(
"jdbc:postgresql://" + credentials.getHost() + "/"
"jdbc:postgresql://" + credentials.getHost() + ":" + credentials.getPort() + "/"
+ credentials.getDatabase(),
// + "?logLevel=2"
credentials.getUser(),
Expand Down
6 changes: 3 additions & 3 deletions package/bin/osmosis
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ Example Usage

Import a planet file into a local PostgreSQL database.

osmosis --read-xml file=~/osm/planbet/planet.osm --write-apidb host="x" database="x" user="x" password="x"
osmosis --read-xml file=~/osm/planbet/planet.osm --write-apidb host="x" port="x" database="x" user="x" password="x"

Export a planet file from a local PostgreSQL database.

osmosis --read-apidb host="x" database="x" user="x" password="x" --write-xml file="planet.osm"
osmosis --read-apidb host="x" port="x" database="x" user="x" password="x" --write-xml file="planet.osm"

Derive a change set between two planet files.

osmosis --read-xml file="planet2.osm" --read-xml file="planet1.osm" --derive-change --write-xml-change file="planetdiff-1-2.osc"

Derive a change set between a planet file and a database.

osmosis --read-mysql host="x" database="x" user="x" password="x" --read-xml file="planet1.osm" --derive-change --write-xml-change file="planetdiff-1-2.osc"
osmosis --read-mysql host="x" port="x" database="x" user="x" password="x" --read-xml file="planet1.osm" --derive-change --write-xml-change file="planetdiff-1-2.osc"

Apply a change set to a planet file.

Expand Down