it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoserver-manager Show documentation
Show all versions of geoserver-manager Show documentation
GeoServer Manager is a library to interact with GeoServer
The scope of this library is to have a simple API, and use as few external
libs as possible.
The newest version!
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.datastore;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
/**
* Encoder for an {@value #TYPE} datastore.
*
* @author Gianni Barrotta
* @author Oscar Fonts
* @version $Id: $
*/
public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final String TYPE = "Oracle NG";
static final String DEFAULT_DB_TYPE = "oracle";
static final int DEFAULT_MIN_CONNECTIONS = 1;
static final int DEFAULT_MAX_CONNECTIONS = 10;
static final int DEFAULT_FETCH_SIZE = 1000;
static final int DEFAULT_CONNECTION_TIMEOUT = 20;
static final boolean DEFAULT_LOOSE_BBOX = true;
static final boolean DEFAULT_PREPARED_STATEMENTS = true;
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
static final boolean DEFAULT_ESTIMATED_EXTENDS = false;
/**
* Create an {@value #TYPE} datastore with default connection parameters,
* given a store name, and a database name.
*
* The following default connection parameters are set:
*
* - min connections: {@value #DEFAULT_MIN_CONNECTIONS}
*
- max connections: {@value #DEFAULT_MAX_CONNECTIONS}
*
- fetch size: {@value #DEFAULT_FETCH_SIZE}
*
- Connection timeout: {@value #DEFAULT_CONNECTION_TIMEOUT}
*
- Loose bbox: {@value #DEFAULT_LOOSE_BBOX}
*
- preparedStatements: {@value #DEFAULT_PREPARED_STATEMENTS}
*
- Max open prepared statements: {@value #DEFAULT_MAX_OPEN_PREPARED_STATEMENTS}
*
*
* @param name New datastore name
* @param database a {@link java.lang.String} object.
*/
public GSOracleNGDatastoreEncoder(String name, String database) {
super(name);
// Set mandatory parameter
setType(TYPE);
setDatabaseType(DEFAULT_DB_TYPE);
setDatabase(database);
// Set default values
setMinConnections(DEFAULT_MIN_CONNECTIONS);
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
setFetchSize(DEFAULT_FETCH_SIZE);
setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
setLooseBBox(DEFAULT_LOOSE_BBOX);
setPreparedStatements(DEFAULT_PREPARED_STATEMENTS);
setMaxOpenPreparedStatements(DEFAULT_MAX_OPEN_PREPARED_STATEMENTS);
setEstimatedExtends(DEFAULT_ESTIMATED_EXTENDS);
}
/**
* Create an {@value #TYPE} datastore encoder from an existing store read from server.
*
* @param store The existing store.
* @throws java.lang.IllegalArgumentException if store type or mandatory parameters are not valid
*/
public GSOracleNGDatastoreEncoder(RESTDataStore store) {
super(store);
// Check mandatory parameter validity
ensureValidDatabase(store.getConnectionParameters().get("database"));
}
/**
* setHost
*
* @param host a {@link java.lang.String} object.
*/
public void setHost(String host) {
connectionParameters.set("host", host);
}
/**
* setPort
*
* @param port a int.
*/
public void setPort(int port) {
connectionParameters.set("port", Integer.toString(port));
}
/**
* setNamespace
*
* @param namespace a {@link java.lang.String} object.
*/
public void setNamespace(String namespace) {
connectionParameters.set("namespace", namespace);
}
/**
* setDatabase
*
* @param database a {@link java.lang.String} object.
*/
public void setDatabase(String database) {
connectionParameters.set("database", database);
}
/**
* setSchema
*
* @param schema a {@link java.lang.String} object.
*/
public void setSchema(String schema) {
connectionParameters.set("schema", schema);
}
/**
* setUser
*
* @param user a {@link java.lang.String} object.
*/
public void setUser(String user) {
connectionParameters.set("user", user);
}
/**
* setPassword
*
* @param password a {@link java.lang.String} object.
*/
public void setPassword(String password) {
connectionParameters.set("passwd", password);
}
/**
* setDatabaseType
*
* @param dbtype a {@link java.lang.String} object.
*/
public void setDatabaseType(String dbtype) {
connectionParameters.set("dbtype", dbtype);
}
/**
* setJndiReferenceName
*
* @param jndiReferenceName a {@link java.lang.String} object.
*/
public void setJndiReferenceName(String jndiReferenceName) {
connectionParameters.set("jndiReferenceName", jndiReferenceName);
}
/**
* setExposePrimaryKeys
*
* @param exposePrimaryKeys a boolean.
*/
public void setExposePrimaryKeys(boolean exposePrimaryKeys) {
connectionParameters.set("Expose primary keys", Boolean.toString(exposePrimaryKeys));
}
/**
* setMaxConnections
*
* @param maxConnections a int.
*/
public void setMaxConnections(int maxConnections) {
connectionParameters.set("max connections", Integer.toString(maxConnections));
}
/**
* setMinConnections
*
* @param minConnections a int.
*/
public void setMinConnections(int minConnections) {
connectionParameters.set("min connections", Integer.toString(minConnections));
}
/**
* setFetchSize
*
* @param fetchSize a int.
*/
public void setFetchSize(int fetchSize) {
connectionParameters.set("fetch size", Integer.toString(fetchSize));
}
/**
* setConnectionTimeout
*
* @param seconds a int.
*/
public void setConnectionTimeout(int seconds) {
connectionParameters.set("Connection timeout", Integer.toString(seconds));
}
/**
* setValidateConnections
*
* @param validateConnections a boolean.
*/
public void setValidateConnections(boolean validateConnections) {
connectionParameters.set("validate connections", Boolean.toString(validateConnections));
}
/**
* setPrimaryKeyMetadataTable
*
* @param primaryKeyMetadataTable a {@link java.lang.String} object.
*/
public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) {
connectionParameters.set("Primary key metadata table", primaryKeyMetadataTable);
}
/**
* setLooseBBox
*
* @param looseBBox a boolean.
*/
public void setLooseBBox(boolean looseBBox) {
connectionParameters.set("Loose bbox", Boolean.toString(looseBBox));
}
/**
* setPreparedStatements
*
* @param preparedStatements a boolean.
*/
public void setPreparedStatements(boolean preparedStatements) {
connectionParameters.set("preparedStatements", Boolean.toString(preparedStatements));
}
/**
* setMaxOpenPreparedStatements
*
* @param maxOpenPreparedStatements a int.
*/
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
}
/**
* setEstimatedExtends
*
* @param estimatedExtends a boolean.
*/
public void setEstimatedExtends(boolean estimatedExtends){
connectionParameters.set("Estimated extends", Boolean.toString(estimatedExtends));
}
/**
* Check database validity.
*
* @param database the database name
* @throws IllegalArgumentException if database is null or empty
*/
private static void ensureValidDatabase(String database) {
if (database == null || database.length() == 0) {
throw new IllegalArgumentException(
"Oracle store database cannot be null or empty");
}
}
/**
* getValidType
*
* @return {@value #TYPE}
*/
protected String getValidType() {
return TYPE;
}
}