Search in sources :

Example 1 with PostgisNGDataStoreFactory

use of org.geotools.data.postgis.PostgisNGDataStoreFactory 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)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)1 ArrayList (java.util.ArrayList)1 PostgisNGDataStoreFactory (org.geotools.data.postgis.PostgisNGDataStoreFactory)1