Search in sources :

Example 21 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection 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;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) ArrayList(java.util.ArrayList) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) GeoPkgDataStoreFactory(org.geotools.geopkg.GeoPkgDataStoreFactory) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) File(java.io.File)

Example 22 with DatabaseConnection

use of com.sldeditor.common.data.DatabaseConnection 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;
}
Also used : DatabaseConnectionField(com.sldeditor.common.data.DatabaseConnectionField) JDTSSQLServerJNDIDataStoreFactory(org.geotools.data.sqlserver.jtds.JDTSSQLServerJNDIDataStoreFactory) ArrayList(java.util.ArrayList) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 23 with DatabaseConnection

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

Example 24 with DatabaseConnection

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

the class DatabaseConnectionFactory method getConnection.

/**
 * Gets the database connection.
 *
 * @param filename the filename
 * @return the new connection
 */
public static DatabaseConnection getConnection(String filename) {
    List<FileHandlerInterface> list = getFileHandlers();
    if (filename != null) {
        for (FileHandlerInterface handler : list) {
            for (String fileExtension : handler.getFileExtensionList()) {
                if (filename.endsWith(fileExtension)) {
                    String dbConnectionType = fileHandlerMap.get(handler);
                    DatabaseConnection dbConnection = createDefault(dbConnectionType);
                    Map<String, String> connectionDataMap = new HashMap<String, String>();
                    connectionDataMap.put(JDBCDataStoreFactory.DATABASE.key, filename);
                    dbConnection.setConnectionDataMap(connectionDataMap);
                    return dbConnection;
                }
            }
        }
    }
    return null;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) HashMap(java.util.HashMap) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Example 25 with DatabaseConnection

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

the class DatabaseConnectionFactory method createTeradata.

/**
 * Creates a new DatabaseConnection object for Teradata.
 *
 * @return the database connection
 */
public static DatabaseConnection createTeradata() {
    List<DatabaseConnectionField> list = new ArrayList<DatabaseConnectionField>();
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.HOST));
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.PORT));
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.USER));
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.SCHEMA));
    list.add(new DatabaseConnectionField(TeradataDataStoreFactory.PASSWD));
    TeradataDataStoreFactory factory = new TeradataDataStoreFactory();
    DatabaseConnection databaseConnection = new DatabaseConnection(TeradataDataStoreFactory.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(TeradataDataStoreFactory.SCHEMA.key), properties.get(TeradataDataStoreFactory.DATABASE.key), properties.get(TeradataDataStoreFactory.HOST.key), properties.get(TeradataDataStoreFactory.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) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection) TeradataDataStoreFactory(org.geotools.data.teradata.TeradataDataStoreFactory)

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