use of com.sldeditor.common.data.DatabaseConnectionField in project sldeditor by robward-scisys.
the class DatabaseConnectionTest method testDatabaseConnection.
/**
* Test method for
* {@link com.sldeditor.common.data.DatabaseConnection#DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)}.
*/
@Test
public void testDatabaseConnection() {
Param param = GeoPkgDataStoreFactory.DBTYPE;
List<DatabaseConnectionField> expectedDetailList = new ArrayList<DatabaseConnectionField>();
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE));
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
String expectedDatabaseTypeLabel = "GeoPackage";
boolean expectedSupportsDuplication = false;
DatabaseConnection test = new DatabaseConnection(param, expectedDatabaseTypeLabel, expectedSupportsDuplication, expectedDetailList, new DatabaseConnectionName() {
@Override
public String getConnectionName(String duplicatePrefix, int noOfDuplicates, Map<String, String> properties) {
String connectionName = Localisation.getString(DatabaseConnectionTest.class, "common.notSet");
String databaseName = properties.get(GeoPkgDataStoreFactory.DATABASE.key);
if (databaseName != null) {
File f = new File(databaseName);
if (f.isFile()) {
connectionName = f.getName();
}
}
for (int i = 0; i < noOfDuplicates; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
Map<String, String> connectionDataMap = new HashMap<String, String>();
connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test datatbase");
test.setConnectionDataMap(connectionDataMap);
assertEquals(test.isSupportsDuplication(), expectedSupportsDuplication);
assertNotNull(test.getConnectionName());
assertNotNull(test.getDatabaseConnectionName());
assertEquals(test.getDetailList(), expectedDetailList);
assertEquals(test.getDatabaseTypeLabel(), expectedDatabaseTypeLabel);
assertTrue(test.hashCode() != 0);
assertEquals(1, test.getExpectedKeys().size());
assertEquals(GeoPkgDataStoreFactory.DATABASE.key, test.getExpectedKeys().get(0));
assertEquals(test.getDatabaseType(), param.sample);
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DATABASE.key), connectionDataMap.get(GeoPkgDataStoreFactory.DATABASE.key));
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DBTYPE.key), GeoPkgDataStoreFactory.DBTYPE.sample);
String expectedUserName = "test user";
test.setUserName(expectedUserName);
assertEquals(test.getUserName(), expectedUserName);
assertNotNull(test.getDBConnectionParams());
String expectedPassword = "password123";
test.setPassword(expectedPassword);
assertEquals(test.getPassword(), expectedPassword);
// Duplicate
DatabaseConnection testCopy = test.duplicate();
assertTrue(testCopy.compareTo(test) < 0);
testCopy.update(test);
assertEquals(testCopy, test);
assertEquals(testCopy, testCopy);
testCopy.setUserName("new username");
assertFalse(testCopy.equals(test));
testCopy.update(test);
assertTrue(testCopy.equals(test));
String actualString = test.encodeAsString();
DatabaseConnection newTest = DatabaseConnection.decodeString(actualString);
assertTrue(newTest.equals(test));
}
use of com.sldeditor.common.data.DatabaseConnectionField in project sldeditor by robward-scisys.
the class DatabaseConnector method setConnection.
/*
* (non-Javadoc)
*
* @see com.sldeditor.tool.dbconnectionlist.DatabaseConnectionConfigInterface#setConnection(com.sldeditor.common.data.DatabaseConnection)
*/
@Override
public void setConnection(DatabaseConnection connection) {
this.databaseConnection = connection;
if (connection != null) {
for (DatabaseConnectionField field : databaseConnection.getDetailList()) {
createField(field);
if (field.isUsername()) {
userKey = field.getKey();
} else if (field.isPassword()) {
passwordKey = field.getKey();
}
}
Map<String, String> properties = connection.getConnectionDataMap();
for (String fieldName : textFieldMap.keySet()) {
JTextField textField = textFieldMap.get(fieldName);
textField.setText(properties.get(fieldName));
}
if (userKey != null) {
JTextField textField = textFieldMap.get(userKey);
textField.setText(connection.getUserName());
}
if (passwordKey != null) {
JTextField textField = textFieldMap.get(passwordKey);
textField.setText(connection.getPassword());
}
}
}
use of com.sldeditor.common.data.DatabaseConnectionField in project sldeditor by robward-scisys.
the class DatabaseConnectionFactory method createGeoPackage.
/**
* Creates a new DatabaseConnection object for a GeoPackage.
*
* @return the database connection
*/
public static DatabaseConnection createGeoPackage() {
List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(DatabaseConnector.class, "DatabaseConnectorGeoPkg.fileExtension") + " (*." + GEOPACKAGE_FILE_EXTENSION + ")", GEOPACKAGE_FILE_EXTENSION);
list.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE, filter));
list.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
GeoPkgDataStoreFactory factory = new GeoPkgDataStoreFactory();
DatabaseConnection databaseConnection = new DatabaseConnection(GeoPkgDataStoreFactory.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.DatabaseConnectionField in project sldeditor by robward-scisys.
the class DatabaseConnectionFactory method createSQLServer.
/**
* Creates a new DatabaseConnection object for SQL Server.
*
* @return the database connection
*/
public static DatabaseConnection createSQLServer() {
List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.HOST));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.PORT));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.INSTANCE));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.SCHEMA));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.DATABASE));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.USER));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.PASSWD));
list.add(new DatabaseConnectionField(JTDSSqlServerDataStoreFactory.GEOMETRY_METADATA_TABLE));
JDTSSQLServerJNDIDataStoreFactory factory = new JDTSSQLServerJNDIDataStoreFactory();
DatabaseConnection databaseConnection = new DatabaseConnection(JTDSSqlServerDataStoreFactory.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(JTDSSqlServerDataStoreFactory.INSTANCE.key), properties.get(JTDSSqlServerDataStoreFactory.DATABASE.key), properties.get(JTDSSqlServerDataStoreFactory.HOST.key), properties.get(JTDSSqlServerDataStoreFactory.PORT.key));
for (int i = 0; i < noOfTimesDuplicated; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
return databaseConnection;
}
use of com.sldeditor.common.data.DatabaseConnectionField in project sldeditor by robward-scisys.
the class DatabaseConnectionFactory method createPostgres.
/**
* Creates a new DatabaseConnection object for Postgres.
*
* @return the database connection
*/
public static DatabaseConnection createPostgres() {
List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.HOST));
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.PORT));
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.DATABASE));
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.SCHEMA));
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.USER));
list.add(new DatabaseConnectionField(PostgisNGDataStoreFactory.PASSWD));
PostgisNGDataStoreFactory factory = new PostgisNGDataStoreFactory();
DatabaseConnection databaseConnection = new DatabaseConnection(PostgisNGDataStoreFactory.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(PostgisNGDataStoreFactory.SCHEMA.key), properties.get(PostgisNGDataStoreFactory.DATABASE.key), properties.get(PostgisNGDataStoreFactory.HOST.key), properties.get(PostgisNGDataStoreFactory.PORT.key));
for (int i = 0; i < noOfTimesDuplicated; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
return databaseConnection;
}
Aggregations