org.gcube.portlets.user.tdw.server.datasource.jdbc
Class JDBCDataSource

java.lang.Object
  extended by 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"

Field Summary
protected  ColumnDefinition autogeneratePrimaryColumn
           
protected  Connection connection
           
protected  String dataSourceFactoryId
           
protected  SQLDialect dialect
           
static String JSON_OFFSET_FIELD
           
static String JSON_ROWS_FIELD
           
static String JSON_TOTAL_LENGTH_FIELD
           
protected  TableJSonBuilder jsonBuilder
           
protected  org.apache.log4j.Logger logger
           
protected  Map<String,PreparedStatement> preparedStatementCache
           
protected  TableDefinition tableDefinition
           
protected  String tableName
           
protected  int tableSize
           
 
Constructor Summary
JDBCDataSource(String dataSourceFactoryId, Connection connection, String tableName)
           
JDBCDataSource(String dataSourceFactoryId, String jdbcConnectionUrl, String tableName)
           
 
Method Summary
protected  int calculateTableSize()
           
 void close()
          Close this DataSource releasing all the allocated resources.
protected  ColumnDefinition createPrimaryKeyColumn(List<ColumnDefinition> columns)
           
protected  TableDefinition extractTableDefinition()
           
protected  TableJSonBuilder getBuilder()
           
protected  ColumnDefinition getColumnDefinition(ResultSet columns)
           
protected  List<ColumnDefinition> getColumnDefinitions()
           
 String getDataAsJSon(int start, int limit, String sortingColumn, Direction direction)
          Retrieves the table data as JSON object.
 String getDataSourceFactoryId()
          Returns the id of the DataSourceFactory that have generated it.
protected  String getJSon(ResultSet resultSet, int start)
           
protected  PreparedStatement getPreparedStatement(String sortingColumn, Direction sortingDirection, int start, int limit)
           
protected  String getPrimaryKey()
           
 TableDefinition getTableDefinition()
          Returns the table definition.
protected  int getTableSize()
           
protected  ValueType getValueType(int sqlType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

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
Method Detail

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.