org.gcube.portlets.user.tdw.server.datasource.jdbc
Class JDBCDataSource
java.lang.Object
org.gcube.portlets.user.tdw.server.datasource.jdbc.JDBCDataSource
- All Implemented Interfaces:
- DataSource
public class JDBCDataSource
- extends Object
- implements DataSource
- Author:
- "Federico De Faveri defaveri@isti.cnr.it"
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JSON_ROWS_FIELD
public static final String JSON_ROWS_FIELD
- See Also:
- Constant Field Values
JSON_TOTAL_LENGTH_FIELD
public static final String JSON_TOTAL_LENGTH_FIELD
- See Also:
- Constant Field Values
JSON_OFFSET_FIELD
public static final String JSON_OFFSET_FIELD
- See Also:
- Constant Field Values
logger
protected org.apache.log4j.Logger logger
dataSourceFactoryId
protected String dataSourceFactoryId
connection
protected Connection connection
dialect
protected SQLDialect dialect
tableName
protected String tableName
tableDefinition
protected TableDefinition tableDefinition
tableSize
protected int tableSize
preparedStatementCache
protected Map<String,PreparedStatement> preparedStatementCache
autogeneratePrimaryColumn
protected ColumnDefinition autogeneratePrimaryColumn
jsonBuilder
protected TableJSonBuilder jsonBuilder
JDBCDataSource
public JDBCDataSource(String dataSourceFactoryId,
Connection connection,
String tableName)
throws DataSourceException
- Throws:
DataSourceException
JDBCDataSource
public JDBCDataSource(String dataSourceFactoryId,
String jdbcConnectionUrl,
String tableName)
throws DataSourceException
- Throws:
DataSourceException
getDataSourceFactoryId
public String getDataSourceFactoryId()
- Returns the id of the
DataSourceFactory that have generated it.
- Specified by:
getDataSourceFactoryId in interface DataSource
- Returns:
- the
DataSourceFactory id.
close
public void close()
throws DataSourceException
- Close this DataSource releasing all the allocated resources.
- Throws:
DataSourceException
getTableDefinition
public TableDefinition getTableDefinition()
throws DataSourceException
- Returns the table definition.
- Specified by:
getTableDefinition in interface DataSource
- Returns:
- a table definition.
- Throws:
DataSourceException - if an error occurred retrieving the table definition.
extractTableDefinition
protected TableDefinition extractTableDefinition()
throws DataSourceException
- Throws:
DataSourceException
getColumnDefinitions
protected List<ColumnDefinition> getColumnDefinitions()
throws SQLException,
DataSourceException
- Throws:
SQLException
DataSourceException
getColumnDefinition
protected ColumnDefinition getColumnDefinition(ResultSet columns)
throws SQLException
- Throws:
SQLException
getPrimaryKey
protected String getPrimaryKey()
throws SQLException,
DataSourceException
- Throws:
SQLException
DataSourceException
createPrimaryKeyColumn
protected ColumnDefinition createPrimaryKeyColumn(List<ColumnDefinition> columns)
getValueType
protected ValueType getValueType(int sqlType)
getDataAsJSon
public String getDataAsJSon(int start,
int limit,
String sortingColumn,
Direction direction)
throws DataSourceException
- Retrieves the table data as JSON object.
- Specified by:
getDataAsJSon in interface DataSource
- Parameters:
start - the starting row index.limit - the number of rows after the starting index to retrieve.sortingColumn - the column used for sorting.direction - the sorting direction.
- Returns:
- the JSON object as String.
- Throws:
DataSourceException - if an error occurred retrieving the table data.
getPreparedStatement
protected PreparedStatement getPreparedStatement(String sortingColumn,
Direction sortingDirection,
int start,
int limit)
throws DataSourceException,
SQLException
- Throws:
DataSourceException
SQLException
getJSon
protected String getJSon(ResultSet resultSet,
int start)
throws SQLException,
DataSourceException
- Throws:
SQLException
DataSourceException
getBuilder
protected TableJSonBuilder getBuilder()
throws DataSourceException
- Throws:
DataSourceException
getTableSize
protected int getTableSize()
throws DataSourceException
- Throws:
DataSourceException
calculateTableSize
protected int calculateTableSize()
throws DataSourceException
- Throws:
DataSourceException
Copyright © 2013. All Rights Reserved.