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);
}
}
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;
}
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;
}
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;
}
Aggregations