public class ConnectionManager extends Object
Manages database URLs contained in the database.properties file. It's possible to define more than one database URL in the file or to load connection attributes from another file.
You can change the path of the database.properties file by setting the system property attribute "databases.properties.path" to the desired file path.
| Constructor and Description |
|---|
ConnectionManager() |
| Modifier and Type | Method and Description |
|---|---|
Connection |
createConnection()
Creates a connection using the default connection string.
|
Connection |
createConnection(String name)
Creates a connection using the specified connection name.
|
String |
getDefault()
Gets the default database.url name.
|
String |
getFilePath()
Get the file path to the actual database property file.
|
String |
getUrl()
Gets the default database URL (the database.url.
|
String |
getUrl(String name)
Get the specified connection string.
|
boolean |
isSplit() |
boolean |
isSplit(String name) |
void |
loadAttributes()
Loads the default attribute file as defined by the system property
"databases.properties.path".
|
void |
loadAttributes(String filePath)
Load the specified attribute file.
|
void |
saveAttributes()
Saves the default attribute file as defined by
ConnectionManager.FILE_PATH.
|
void |
saveAttributes(String filePath)
Saves the changes to the attribute file specified.
|
void |
setDefault(String name)
Sets the default database url name.
|
void |
setSplit(boolean value) |
void |
setSplit(String name,
boolean value) |
void |
setUrl(String url)
Sets the default database URL.
|
void |
setUrl(String name,
String url)
Sets the url value to the database.url.
|
public void loadAttributes()
throws IOException
IOException - if the file does not exist.public void loadAttributes(String filePath) throws IOException
filePath - Path to the file to load.IOException - if the file does not exist.public void saveAttributes()
throws IOException
IOException - if there is a problem during the save operation.public void saveAttributes(String filePath) throws IOException
filePath - The path to the file to be saved.IOException - if there is a problem during the save operation.public Connection createConnection() throws SQLException
SQLException - if there is a problem connecting to the database or if the
connection string is invalid.public Connection createConnection(String name) throws SQLException
name - The name of the connection to create.SQLException - if there is a problem connecting to the database or if the
connection string is invalid.public String getFilePath()
public String getUrl(String name)
name - The name of the connection string to get.public void setUrl(String name, String url)
name - The name of the connection.url to set.url - the url value.public String getUrl()
String containing the database URL.public void setUrl(String url)
url - The url to set to the default database.url attribute.public boolean isSplit()
public void setSplit(boolean value)
public boolean isSplit(String name)
public void setSplit(String name, boolean value)
public String getDefault()
public void setDefault(String name)
name - The name of the default database.url to use.Copyright © 2013. All rights reserved.