Search in sources :

Example 1 with MySQLDataStoreFactory

use of org.geotools.data.mysql.MySQLDataStoreFactory 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)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)1 ArrayList (java.util.ArrayList)1 MySQLDataStoreFactory (org.geotools.data.mysql.MySQLDataStoreFactory)1