Class JdbcDataContext

  • All Implemented Interfaces:
    org.apache.metamodel.DataContext, org.apache.metamodel.UpdateableDataContext

    public class JdbcDataContext
    extends org.apache.metamodel.AbstractDataContext
    implements org.apache.metamodel.UpdateableDataContext
    DataContextStrategy to use for JDBC-compliant databases
    • Constructor Detail

      • JdbcDataContext

        public JdbcDataContext​(DataSource dataSource,
                               org.apache.metamodel.schema.TableType[] tableTypes,
                               String catalogName)
        Creates the strategy based on a data source, some table types and an optional catalogName
        Parameters:
        dataSource - the datasource objcet to use for making connections
        tableTypes - the types of tables to include
        catalogName - a catalog name to use, can be null
      • JdbcDataContext

        public JdbcDataContext​(Connection connection,
                               org.apache.metamodel.schema.TableType[] tableTypes,
                               String catalogName)
        Creates the strategy based on a Connection, some table types and an optional catalogName
        Parameters:
        connection - the database connection
        tableTypes - the types of tables to include
        catalogName - a catalog name to use, can be null
      • JdbcDataContext

        public JdbcDataContext​(Connection connection)
        Creates the strategy based on a Connection
        Parameters:
        connection - the database connection
      • JdbcDataContext

        public JdbcDataContext​(DataSource dataSource)
        Creates the strategy based on a DataSource
        Parameters:
        dataSource - the data source
    • Method Detail

      • compileQuery

        public org.apache.metamodel.query.CompiledQuery compileQuery​(org.apache.metamodel.query.Query query)
        Specified by:
        compileQuery in interface org.apache.metamodel.DataContext
        Overrides:
        compileQuery in class org.apache.metamodel.AbstractDataContext
      • executeQuery

        public org.apache.metamodel.data.DataSet executeQuery​(org.apache.metamodel.query.CompiledQuery compiledQuery,
                                                              Object... values)
        Specified by:
        executeQuery in interface org.apache.metamodel.DataContext
        Overrides:
        executeQuery in class org.apache.metamodel.AbstractDataContext
      • executeQuery

        public org.apache.metamodel.data.DataSet executeQuery​(org.apache.metamodel.query.Query query)
                                                       throws org.apache.metamodel.MetaModelException
        Specified by:
        executeQuery in interface org.apache.metamodel.DataContext
        Throws:
        org.apache.metamodel.MetaModelException
      • executeQuery

        protected org.apache.metamodel.data.DataSet executeQuery​(Connection connection,
                                                                 org.apache.metamodel.query.Query query,
                                                                 boolean closeConnectionOnCloseDataSet)
      • close

        public void close​(Connection connection)
        Quietly closes the connection
        Parameters:
        connection - The connection to close (if it makes sense, @see closeIfNecessary)
      • getCatalogNames

        public String[] getCatalogNames()
        Convenience method to get the available catalogNames using this connection.
        Returns:
        a String-array with the names of the available catalogs.
      • getDelegate

        public Object getDelegate()
        Gets the delegate from the JDBC API (ie. Connection or DataSource) that is being used to perform database interactions.
        Returns:
        either a DataSource or a Connection, depending on the configuration of the DataContext.
      • getConnection

        public Connection getConnection()
        Gets an appropriate connection object to use - either a dedicated connection or a new connection from the datasource object. Hint: Use the close(Connection) method to close the connection (and any ResultSet or Statements involved).
      • getDefaultSchemaName

        public String getDefaultSchemaName()
        Specified by:
        getDefaultSchemaName in class org.apache.metamodel.AbstractDataContext
      • getIdentifierQuoteString

        public String getIdentifierQuoteString()
      • getSchemaNamesInternal

        protected List<String> getSchemaNamesInternal()
        Specified by:
        getSchemaNamesInternal in class org.apache.metamodel.AbstractDataContext
      • getSchemaByNameInternal

        protected org.apache.metamodel.schema.Schema getSchemaByNameInternal​(String name)
        Specified by:
        getSchemaByNameInternal in class org.apache.metamodel.AbstractDataContext
      • getFetchSizeCalculator

        public org.apache.metamodel.jdbc.FetchSizeCalculator getFetchSizeCalculator()
      • executeUpdate

        public org.apache.metamodel.UpdateSummary executeUpdate​(org.apache.metamodel.UpdateScript update)
                                                         throws RolledBackUpdateException
        Specified by:
        executeUpdate in interface org.apache.metamodel.UpdateableDataContext
        Throws:
        RolledBackUpdateException - when a potentially retriable SQLException was thrown during the execution of the update script.
      • isSingleConnection

        protected boolean isSingleConnection()
      • isDefaultAutoCommit

        protected boolean isDefaultAutoCommit()
      • isQualifiedPathDelim

        protected boolean isQualifiedPathDelim​(char c)
        Overrides:
        isQualifiedPathDelim in class org.apache.metamodel.AbstractDataContext
      • getTableTypes

        public org.apache.metamodel.schema.TableType[] getTableTypes()
      • getCatalogName

        public String getCatalogName()
      • getDatabaseProductName

        public String getDatabaseProductName()
      • getDatabaseVersion

        public String getDatabaseVersion()