Search in sources :

Example 1 with DB2NGDataStoreFactory

use of org.geotools.data.db2.DB2NGDataStoreFactory 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)

Aggregations

DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 DatabaseConnectionField (com.sldeditor.common.data.DatabaseConnectionField)1 ArrayList (java.util.ArrayList)1 Param (org.geotools.data.DataAccessFactory.Param)1 DB2NGDataStoreFactory (org.geotools.data.db2.DB2NGDataStoreFactory)1