Search in sources :

Example 11 with DatabaseConnection

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;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) OracleNGDataStoreFactory(org.geotools.data.oracle.OracleNGDataStoreFactory) ArrayList(java.util.ArrayList) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 12 with 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;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) ArrayList(java.util.ArrayList) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) SpatiaLiteDataStoreFactory(org.geotools.data.spatialite.SpatiaLiteDataStoreFactory) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) File(java.io.File)

Example 13 with 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;
}
Also used : HashMap(java.util.HashMap) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) JTextField(javax.swing.JTextField)

Example 14 with DatabaseConnection

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);
}
Also used : HashMap(java.util.HashMap) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

Example 15 with DatabaseConnection

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());
}
Also used : DatabaseConnector(com.sldeditor.tool.dbconnectionlist.DatabaseConnector) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) Test(org.junit.Test)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)33 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)11 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)10 HashMap (java.util.HashMap)10 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)7 File (java.io.File)6 NodeInterface (com.sldeditor.common.NodeInterface)3 DatabaseNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 DatabaseFeatureClassNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseFeatureClassNode)2 DatabaseOverallNode (com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)2 FileNotFoundException (java.io.FileNotFoundException)2 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 Param (org.geotools.data.DataAccessFactory.Param)2 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1