Search in sources :

Example 6 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionTool method connect.

/**
 * Connect.
 */
protected void connect() {
    if (databaseConnectState != null) {
        connectButton.setEnabled(false);
        disconnectButton.setEnabled(false);
        databaseConnectState.connect(connectionList);
        for (DatabaseConnection connection : connectionList) {
            if (!databaseConnectState.isConnected(connection)) {
                connectButton.setEnabled(true);
            }
        }
    }
}
Also used : DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 7 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionTool method setSelectedItems.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.tool.ToolInterface#setSelectedItems(java.util.List, java.util.List)
     */
@Override
public void setSelectedItems(List<NodeInterface> nodeTypeList, List<SLDDataInterface> sldDataList) {
    connectionList.clear();
    if (nodeTypeList != null) {
        for (NodeInterface node : nodeTypeList) {
            if (node instanceof DatabaseNode) {
                DatabaseNode databaseNode = (DatabaseNode) node;
                connectionList.add(databaseNode.getConnection());
            } else if (node instanceof FileTreeNode) {
                FileTreeNode fileNode = (FileTreeNode) node;
                if (fileNode.getFileCategory() == FileTreeNodeTypeEnum.DATABASE) {
                    DatabaseConnection databaseConnection = DatabaseConnectionFactory.getConnection(fileNode.getFile().getAbsolutePath());
                    connectionList.add(databaseConnection);
                }
            }
        }
    }
    updateButtonState();
}
Also used : DatabaseNode(com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) NodeInterface(com.sldeditor.common.NodeInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 8 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method createDB2.

/**
 * Creates a new DatabaseConnection object for DB2.
 *
 * @return the database connection
 */
public static DatabaseConnection createDB2() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.HOST));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.PORT));
    Param TABSCHEMA = new Param("tabschema", String.class, "Schema", false);
    list.add(new DatabaseConnectionField(TABSCHEMA));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.USER));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.PASSWD));
    DB2NGDataStoreFactory factory = new DB2NGDataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(DB2NGDataStoreFactory.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("tabschema"), properties.get(JDBCDataStoreFactory.DATABASE.key), properties.get(JDBCDataStoreFactory.HOST.key), properties.get(JDBCDataStoreFactory.PORT.key));
            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) Param(org.geotools.data.DataAccessFactory.Param) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) DB2NGDataStoreFactory(org.geotools.data.db2.DB2NGDataStoreFactory)

Example 9 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method createMySQL.

/**
 * Creates a new DatabaseConnection object for MySQL.
 *
 * @return the database connection
 */
public static DatabaseConnection createMySQL() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.HOST));
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.PORT));
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.STORAGE_ENGINE));
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.USER));
    list.add(new DatabaseConnectionField(MySQLDataStoreFactory.PASSWD));
    MySQLDataStoreFactory factory = new MySQLDataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(MySQLDataStoreFactory.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", properties.get(MySQLDataStoreFactory.DATABASE.key), properties.get(MySQLDataStoreFactory.HOST.key), properties.get(MySQLDataStoreFactory.PORT.key));
            for (int i = 0; i < noOfTimesDuplicated; i++) {
                connectionName = duplicatePrefix + connectionName;
            }
            return connectionName;
        }
    });
    return databaseConnection;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) MySQLDataStoreFactory(org.geotools.data.mysql.MySQLDataStoreFactory) ArrayList(java.util.ArrayList) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 10 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method createH2.

/**
 * Creates a new DatabaseConnection object for H2.
 *
 * @return the database connection
 */
public static DatabaseConnection createH2() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(H2DataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(H2DataStoreFactory.USER));
    H2DataStoreFactory factory = new H2DataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(H2DataStoreFactory.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) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) H2DataStoreFactory(org.geotools.data.h2.H2DataStoreFactory) File(java.io.File)

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