Search in sources :

Example 1 with DatabaseConnectionField

use of com.sldeditor.common.data.DatabaseConnectionField 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 2 with DatabaseConnectionField

use of com.sldeditor.common.data.DatabaseConnectionField 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 3 with DatabaseConnectionField

use of com.sldeditor.common.data.DatabaseConnectionField 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)

Example 4 with DatabaseConnectionField

use of com.sldeditor.common.data.DatabaseConnectionField 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 5 with DatabaseConnectionField

use of com.sldeditor.common.data.DatabaseConnectionField 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)

Aggregations

DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)11 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)10 ArrayList (java.util.ArrayList)10 File (java.io.File)4 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)2 Param (org.geotools.data.DataAccessFactory.Param)2 DatabaseConnectionName (com.sldeditor.tool.dbconnectionlist.DatabaseConnectionName)1 HashMap (java.util.HashMap)1 JTextField (javax.swing.JTextField)1 DB2NGDataStoreFactory (org.geotools.data.db2.DB2NGDataStoreFactory)1 H2DataStoreFactory (org.geotools.data.h2.H2DataStoreFactory)1 MySQLDataStoreFactory (org.geotools.data.mysql.MySQLDataStoreFactory)1 OracleNGDataStoreFactory (org.geotools.data.oracle.OracleNGDataStoreFactory)1 PostgisNGDataStoreFactory (org.geotools.data.postgis.PostgisNGDataStoreFactory)1 SpatiaLiteDataStoreFactory (org.geotools.data.spatialite.SpatiaLiteDataStoreFactory)1 JDTSSQLServerJNDIDataStoreFactory (org.geotools.data.sqlserver.jtds.JDTSSQLServerJNDIDataStoreFactory)1 TeradataDataStoreFactory (org.geotools.data.teradata.TeradataDataStoreFactory)1 GeoPkgDataStoreFactory (org.geotools.geopkg.GeoPkgDataStoreFactory)1 Test (org.junit.Test)1