Search in sources :

Example 1 with JDBCDataStore

use of org.geotools.jdbc.JDBCDataStore in project GeoGig by boundlessgeo.

the class AbstractSLCommand method getDataStore.

/**
     * Constructs a new SpatiaLite data store using connection parameters from {@link SLCommonArgs}.
     * 
     * @return the constructed data store
     * @throws CommandFailedException
     * @see DataStore
     */
protected DataStore getDataStore() {
    Map<String, Serializable> params = Maps.newHashMap();
    params.put(SpatiaLiteDataStoreFactory.DBTYPE.key, "spatialite");
    params.put(SpatiaLiteDataStoreFactory.DATABASE.key, commonArgs.database);
    params.put(SpatiaLiteDataStoreFactory.USER.key, commonArgs.username);
    try {
        DataStore dataStore = dataStoreFactory.createDataStore(params);
        if (dataStore == null) {
            throw new CommandFailedException("Unable to connect using the specified database parameters.");
        }
        if (dataStore instanceof JDBCDataStore) {
            Connection con = null;
            con = ((JDBCDataStore) dataStore).getDataSource().getConnection();
            ((JDBCDataStore) dataStore).closeSafe(con);
        }
        return dataStore;
    } catch (IOException e) {
        throw new CommandFailedException("Unable to connect using the specified database parameters.", e);
    } catch (SQLException e) {
        throw new CommandFailedException("Unable to validate the database connection.", e);
    }
}
Also used : Serializable(java.io.Serializable) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) SQLException(java.sql.SQLException) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) DataStore(org.geotools.data.DataStore) Connection(java.sql.Connection) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 2 with JDBCDataStore

use of org.geotools.jdbc.JDBCDataStore in project GeoGig by boundlessgeo.

the class AbstractSQLServerCommand method getDataStore.

/**
     * Constructs a new SQL Server data store using connection parameters from
     * {@link SQLServerCommonArgs}.
     * 
     * @return the constructed data store
     * @throws CommandFailedException
     * @see DataStore
     */
protected DataStore getDataStore() {
    Map<String, Serializable> params = Maps.newHashMap();
    params.put(SQLServerDataStoreFactory.DBTYPE.key, "sqlserver");
    params.put(SQLServerDataStoreFactory.HOST.key, commonArgs.host);
    params.put(SQLServerDataStoreFactory.PORT.key, commonArgs.port.toString());
    params.put(SQLServerDataStoreFactory.INTSEC.key, commonArgs.intsec);
    params.put(SQLServerDataStoreFactory.SCHEMA.key, commonArgs.schema);
    params.put(SQLServerDataStoreFactory.DATABASE.key, commonArgs.database);
    params.put(SQLServerDataStoreFactory.USER.key, commonArgs.username);
    params.put(SQLServerDataStoreFactory.PASSWD.key, commonArgs.password);
    params.put(SQLServerDataStoreFactory.FETCHSIZE.key, 1000);
    if (!commonArgs.geometryMetadataTable.equals(""))
        params.put(SQLServerDataStoreFactory.GEOMETRY_METADATA_TABLE.key, commonArgs.geometryMetadataTable);
    DataStore dataStore;
    try {
        dataStore = dataStoreFactory.createDataStore(params);
    } catch (IOException e) {
        throw new CommandFailedException("Unable to connect using the specified database parameters.", e);
    }
    if (dataStore == null) {
        throw new CommandFailedException("No suitable data store found for the provided parameters");
    }
    if (dataStore instanceof JDBCDataStore) {
        Connection con = null;
        try {
            con = ((JDBCDataStore) dataStore).getDataSource().getConnection();
        } catch (Exception e) {
            throw new CommandFailedException("Error validating the database connection", e);
        }
        ((JDBCDataStore) dataStore).closeSafe(con);
    }
    return dataStore;
}
Also used : Serializable(java.io.Serializable) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) DataStore(org.geotools.data.DataStore) Connection(java.sql.Connection) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 3 with JDBCDataStore

use of org.geotools.jdbc.JDBCDataStore in project GeoGig by boundlessgeo.

the class AbstractPGCommand method getDataStore.

/**
     * Constructs a new PostGIS data store using connection parameters from {@link PGCommonArgs}.
     * 
     * @return the constructed data store
     * @throws Exception
     * @see DataStore
     */
protected DataStore getDataStore() {
    Map<String, Serializable> params = Maps.newHashMap();
    params.put(PostgisNGDataStoreFactory.DBTYPE.key, "postgis");
    params.put(PostgisNGDataStoreFactory.HOST.key, commonArgs.host);
    params.put(PostgisNGDataStoreFactory.PORT.key, commonArgs.port.toString());
    params.put(PostgisNGDataStoreFactory.SCHEMA.key, commonArgs.schema);
    params.put(PostgisNGDataStoreFactory.DATABASE.key, commonArgs.database);
    params.put(PostgisNGDataStoreFactory.USER.key, commonArgs.username);
    params.put(PostgisNGDataStoreFactory.PASSWD.key, commonArgs.password);
    params.put(PostgisNGDataStoreFactory.FETCHSIZE.key, 1000);
    params.put(PostgisNGDataStoreFactory.EXPOSE_PK.key, true);
    DataStore dataStore;
    try {
        dataStore = dataStoreFactory.createDataStore(params);
    } catch (IOException e) {
        throw new CommandFailedException("Unable to connect using the specified database parameters.", e);
    }
    if (dataStore == null) {
        throw new CommandFailedException("Unable to connect using the specified database parameters.");
    }
    if (dataStore instanceof JDBCDataStore) {
        Connection con = null;
        try {
            con = ((JDBCDataStore) dataStore).getDataSource().getConnection();
        } catch (SQLException e) {
            throw new CommandFailedException(e.getMessage(), e);
        }
        ((JDBCDataStore) dataStore).closeSafe(con);
    }
    return dataStore;
}
Also used : Serializable(java.io.Serializable) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) SQLException(java.sql.SQLException) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) DataStore(org.geotools.data.DataStore) Connection(java.sql.Connection) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 4 with JDBCDataStore

use of org.geotools.jdbc.JDBCDataStore in project GeoGig by boundlessgeo.

the class AbstractOracleCommand method getDataStore.

/**
     * Constructs a new Oracle data store using connection parameters from {@link OracleCommonArgs}.
     * 
     * @return the constructed data store
     * @throws Exception
     * @see DataStore
     */
protected DataStore getDataStore() {
    Map<String, Serializable> params = Maps.newHashMap();
    params.put(OracleNGDataStoreFactory.DBTYPE.key, "oracle");
    params.put(OracleNGDataStoreFactory.HOST.key, commonArgs.host);
    params.put(OracleNGDataStoreFactory.PORT.key, commonArgs.port.toString());
    params.put(OracleNGDataStoreFactory.SCHEMA.key, commonArgs.schema);
    params.put(OracleNGDataStoreFactory.DATABASE.key, commonArgs.database);
    params.put(OracleNGDataStoreFactory.USER.key, commonArgs.username);
    params.put(OracleNGDataStoreFactory.PASSWD.key, commonArgs.password);
    // params.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, commonArgs.estimatedExtent);
    // params.put(OracleNGDataStoreFactory.LOOSEBBOX.key, commonArgs.looseBbox);
    // if (!commonArgs.geometryMetadataTable.equals(""))
    // params.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key,
    // commonArgs.geometryMetadataTable);
    // params.put(OracleNGDataStoreFactory.FETCHSIZE.key, 1000);
    DataStore dataStore;
    try {
        dataStore = dataStoreFactory.createDataStore(params);
    } catch (IOException e) {
        throw new CommandFailedException("Unable to connect using the specified database parameters.", e);
    }
    if (dataStore == null) {
        throw new CommandFailedException("No suitable data store found for the provided parameters");
    }
    if (dataStore instanceof JDBCDataStore) {
        Connection con = null;
        try {
            con = ((JDBCDataStore) dataStore).getDataSource().getConnection();
        } catch (Exception e) {
            throw new CommandFailedException("Error validating the database connection", e);
        }
        ((JDBCDataStore) dataStore).closeSafe(con);
    }
    return dataStore;
}
Also used : Serializable(java.io.Serializable) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) JDBCDataStore(org.geotools.jdbc.JDBCDataStore) DataStore(org.geotools.data.DataStore) Connection(java.sql.Connection) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) IOException(java.io.IOException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Aggregations

IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 Connection (java.sql.Connection)4 DataStore (org.geotools.data.DataStore)4 JDBCDataStore (org.geotools.jdbc.JDBCDataStore)4 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)4 SQLException (java.sql.SQLException)2