use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionFactory method createOracle.
/**
* Creates a new DatabaseConnection object for Oracle.
*
* @return the database connection
*/
public static DatabaseConnection createOracle() {
List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.HOST));
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.PORT));
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.SCHEMA));
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.DATABASE));
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.USER));
list.add(new DatabaseConnectionField(OracleNGDataStoreFactory.PASSWD));
OracleNGDataStoreFactory factory = new OracleNGDataStoreFactory();
DatabaseConnection databaseConnection = new DatabaseConnection(OracleNGDataStoreFactory.DBTYPE, factory.getDisplayName(), true, list, new DatabaseConnectionName() {
@Override
public String getConnectionName(String duplicatePrefix, int noOfTimesDuplicated, Map<String, String> properties) {
String connectionName = String.format("%s/%s@%s:%s", properties.get(OracleNGDataStoreFactory.SCHEMA.key), properties.get(OracleNGDataStoreFactory.DATABASE.key), properties.get(OracleNGDataStoreFactory.HOST.key), properties.get(OracleNGDataStoreFactory.PORT.key));
for (int i = 0; i < noOfTimesDuplicated; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
return databaseConnection;
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionFactory method createSpatiaLite.
/**
* Creates a new DatabaseConnection object for a GeoPackage.
*
* @return the database connection
*/
public static DatabaseConnection createSpatiaLite() {
List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
list.add(new DatabaseConnectionField(SpatiaLiteDataStoreFactory.DATABASE));
FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(DatabaseConnector.class, "DatabaseConnectorGeoPkg.fileExtension") + " (*." + SPATIALITE_FILE_EXTENSION + ")", SPATIALITE_FILE_EXTENSION);
list.add(new DatabaseConnectionField(SpatiaLiteDataStoreFactory.USER, filter));
SpatiaLiteDataStoreFactory factory = new SpatiaLiteDataStoreFactory();
DatabaseConnection databaseConnection = new DatabaseConnection(SpatiaLiteDataStoreFactory.DBTYPE, factory.getDisplayName(), false, list, new DatabaseConnectionName() {
@Override
public String getConnectionName(String duplicatePrefix, int noOfTimesDuplicated, Map<String, String> properties) {
String connectionName = Localisation.getString(DatabaseConnectionFactory.class, "common.notSet");
String databaseName = properties.get(JDBCDataStoreFactory.DATABASE.key);
if (databaseName != null) {
File f = new File(databaseName);
if (f.isFile()) {
connectionName = f.getName();
}
}
for (int i = 0; i < noOfTimesDuplicated; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
return databaseConnection;
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnector method getConnection.
/*
* (non-Javadoc)
*
* @see com.sldeditor.tool.dbconnectionlist.DatabaseConnectionConfigInterface#getConnection()
*/
@Override
public DatabaseConnection getConnection() {
DatabaseConnection connectionData = DatabaseConnectionFactory.getNewConnection(databaseConnection);
if (connectionData != null) {
Map<String, String> sourceMap = new HashMap<String, String>();
for (String fieldName : textFieldMap.keySet()) {
boolean isUserName = false;
if (userKey != null) {
isUserName = fieldName.equals(userKey);
}
boolean isPassword = false;
if (passwordKey != null) {
isPassword = fieldName.equals(passwordKey);
}
if (!(isUserName || isPassword)) {
JTextField textField = textFieldMap.get(fieldName);
sourceMap.put(fieldName, textField.getText());
}
}
if (userKey != null) {
JTextField textField = textFieldMap.get(userKey);
connectionData.setUserName(textField.getText());
}
if (passwordKey != null) {
JTextField textField = textFieldMap.get(passwordKey);
connectionData.setPassword(textField.getText());
}
connectionData.setConnectionDataMap(sourceMap);
}
return connectionData;
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseInputTest method testSetFolder.
/**
* Test method for
* {@link com.sldeditor.extension.filesystem.database.DatabaseInput#setFolder(com.sldeditor.common.data.DatabaseConnection, boolean)}.
*/
@Test
public void testSetFolder() {
DatabaseInput input = new DatabaseInput(null);
// Add some database connections
DatabaseConnection connection1 = DatabaseConnectionFactory.createGeoPackage();
Map<String, String> connectionDataMap = new HashMap<String, String>();
connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test.gpkg");
connection1.setConnectionDataMap(connectionDataMap);
input.setFolder(connection1, true);
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectorTest method testDatabaseConnector.
/**
* Test method for {@link com.sldeditor.tool.dbconnectionlist.DatabaseConnector#DatabaseConnector()}.
*/
@Test
public void testDatabaseConnector() {
DatabaseConnector testObj = new DatabaseConnector();
DatabaseConnection connection = DatabaseConnectionFactory.createPostgres();
testObj.setConnection(connection);
DatabaseConnection connection2 = testObj.getConnection();
assertNotNull(connection2);
assertNotNull(testObj.getPanel());
}
Aggregations