Search in sources :

Example 1 with DatabaseClientInterface

use of com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface in project sldeditor by robward-scisys.

the class DatabaseConnectionManager method createDatabaseClient.

/**
 * Creates the database client.
 *
 * @param progress the progress
 * @param connection the connection
 * @return the database client
 */
private DatabaseClientInterface createDatabaseClient(DatabaseReadProgressInterface progress, DatabaseConnection connection) {
    for (DatabaseClientInterface client : databaseClientClassList) {
        if (client.accept(connection)) {
            DatabaseClientInterface newClient = null;
            try {
                newClient = (DatabaseClientInterface) Class.forName(client.getClass().getName()).newInstance();
                newClient.initialise(progress, connection);
                return newClient;
            } catch (InstantiationException e) {
                ConsoleManager.getInstance().exception(DatabaseInput.class, e);
            } catch (IllegalAccessException e) {
                ConsoleManager.getInstance().exception(DatabaseInput.class, e);
            } catch (ClassNotFoundException e) {
                ConsoleManager.getInstance().exception(DatabaseInput.class, e);
            }
        }
    }
    return null;
}
Also used : DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DatabaseInput(com.sldeditor.extension.filesystem.database.DatabaseInput)

Example 2 with DatabaseClientInterface

use of com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface in project sldeditor by robward-scisys.

the class DatabaseInput method connectToDatabase.

/**
 * Connect to database.
 *
 * @param connection the connection
 * @return true, if successful
 */
private boolean connectToDatabase(DatabaseConnection connection) {
    boolean isConnected = false;
    DatabaseConnection dbConnection = DatabaseConnectionManager.getInstance().getMatchingConnection(connection);
    if (dbConnection == null) {
        addNewConnection(connection);
        dbConnection = connection;
    }
    DatabaseClientInterface client = DatabaseConnectionManager.getInstance().getConnectionMap().get(dbConnection);
    if (client != null) {
        client.connect();
        if (client.isConnected()) {
            String message = String.format("%s : %s", Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.connected"), dbConnection.getConnectionName());
            ConsoleManager.getInstance().information(GeoServerConnectionTool.class, message);
            client.retrieveData();
            isConnected = true;
        } else {
            String errorMessage = String.format("%s : %s", Localisation.getString(GeoServerConnectionTool.class, "GeoServerConnectionTool.failedToConnect"), dbConnection.getConnectionName());
            ConsoleManager.getInstance().error(GeoServerConnectionTool.class, errorMessage);
        }
    }
    return isConnected;
}
Also used : GeoServerConnectionTool(com.sldeditor.tool.geoserverconnection.GeoServerConnectionTool) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 3 with DatabaseClientInterface

use of com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface in project sldeditor by robward-scisys.

the class DatabaseInput method deleteConnections.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.datasource.extension.filesystem.DatabaseConnectUpdateInterface#deleteConnections(java.util.List)
     */
@Override
public void deleteConnections(List<DatabaseConnection> connectionList) {
    if (connectionList == null) {
        return;
    }
    List<DefaultMutableTreeNode> overallNodesToRefresh = new ArrayList<DefaultMutableTreeNode>();
    String overallNodeName = null;
    for (DatabaseConnection connection : connectionList) {
        logger.debug("Deleting connection : " + connection.getConnectionName());
        DatabaseClientInterface client = DatabaseConnectionManager.getInstance().getConnectionMap().get(connection);
        if (client != null) {
            disconnectFromDatabase(client);
            featureClassMap.remove(connection);
            DatabaseConnectionManager.getInstance().removeConnection(connection);
            progress.deleteConnection(connection);
            DefaultMutableTreeNode overallNode = getRootDatabaseNode(connection);
            if (!overallNodesToRefresh.contains(overallNode)) {
                overallNodesToRefresh.add(overallNode);
            }
            overallNodeName = connection.getDatabaseTypeLabel();
        }
    }
    updatePropertyFile();
    for (DefaultMutableTreeNode overallNode : overallNodesToRefresh) {
        progress.refreshNode(overallNode);
    }
    progress.setFolder(overallNodeName, null, false);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 4 with DatabaseClientInterface

use of com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface in project sldeditor by robward-scisys.

the class VectorTool method importFeatureClass.

/**
 * Import feature class.
 *
 * @param featureClassNode the feature class node
 * @return true, if successful
 */
protected boolean importFeatureClass(DatabaseFeatureClassNode featureClassNode) {
    if (featureClassNode != null) {
        DatabaseClientInterface dbClient = DatabaseConnectionManager.getInstance().getConnectionMap().get(featureClassNode.getConnectionData());
        if (dbClient != null) {
            ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.createSymbol"), featureClassNode.toString()));
            SLDDataInterface sldData = vectorReader.createVectorSLDData(featureClassNode.getConnectionData(), featureClassNode.toString());
            DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
            DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(dbClient.getClass());
            dsProperties = dsc.getDataSourceProperties(dbClient.getDBConnectionParams());
            dsProperties.setFilename(featureClassNode.toString());
            loadSymbol(dsProperties, sldData, featureClassNode.toString(), featureClassNode.getConnectionData().getConnectionName());
        }
    }
    return false;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface)

Example 5 with DatabaseClientInterface

use of com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface in project sldeditor by robward-scisys.

the class VectorTool method setDataSource.

/**
 * Sets the data source.
 *
 * @param featureClassNode the new data source
 */
protected void setDataSource(DatabaseFeatureClassNode featureClassNode) {
    DatabaseClientInterface dbClient = DatabaseConnectionManager.getInstance().getConnectionMap().get(featureClassNode.getConnectionData());
    if (dbClient != null) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.setDataSource"), featureClassNode.toString()));
        // Vector file
        DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
        DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(dbClient.getClass());
        dsProperties = dsc.getDataSourceProperties(dbClient.getDBConnectionParams());
        dsProperties.setFilename(featureClassNode.toString());
        SLDEditorFile.getInstance().setDataSource(dsProperties);
        DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
        if (dataSource != null) {
            dataSource.connect(featureClassNode.toString(), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
        }
    }
}
Also used : DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) DatabaseClientInterface(com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface)

Aggregations

DatabaseClientInterface (com.sldeditor.extension.filesystem.database.client.DatabaseClientInterface)6 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)2 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)2 SLDDataInterface (com.sldeditor.common.SLDDataInterface)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1 DatabaseInput (com.sldeditor.extension.filesystem.database.DatabaseInput)1 GeoServerConnectionTool (com.sldeditor.tool.geoserverconnection.GeoServerConnectionTool)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1