Class JdbcConnection
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.core.FoundationObject
com.northconcepts.datapipeline.foundations.jdbc.JdbcConnection
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,JdbcConnectionFactory,Serializable
Describes a database (driver, URL, credentials and driver properties), creates JDBC connections to it
and loads its table, schema and query metadata.
- See Also:
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
internalId, internalName, log, TIMESTAMP_FORMATFields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPEFields inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
XML_SERIALIZED_CLASS_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddProperty(Property property) Adds a property passed to the JDBC driver bycreateConnection().addProperty(String name, String value) Adds a property passed to the JDBC driver bycreateConnection().Adds the query and sets this as its connection.Adds a named SQL query;loadQueries()reads its result columns.addSchema(JdbcSchema jdbcSchema) Adds the table and sets this as its connection.Returns a connection to use; factories fromJdbcConnectionFactory.wrap(Connection)return the same connection on every call.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).Returns the database's catalog names, as filled byloadCatalogAndSchemas().Returns the factorycreateConnection()uses in place of the driver, URL, credentials and properties, or null.Returns the password as encoded by thepassword encoder(hex by default).Indicates if the catalog appears at the start of a qualified table name; null untilloadCatalogAndSchemas()runs.Class<?> getJavaTypeOverride(String databaseTypeName) Returns the Java type override for the database type name, ignoring case, or null if there is none.Returns the listener notified asloadTables(LoadTablesRequest)progresses; never null.getName()Returns the encoder used to store the password (defaults toEncoder.HEX).Returns the password decoded with thepassword encoder.Returns the extra properties passed to the JDBC driver bycreateConnection().static List<JdbcQueryColumn> getQueryColumns(ResultSetMetaData resultSetMetaData, JdbcConnection jdbcConnection) Describes each result column, choosing its Java type from the connection's type overrides or SQL-to-Java type mapper.Returns the database's schemas, as filled byloadCatalogAndSchemas().static StringgetSqlOrderBy(String column) Returns an ORDER BY clause (with a leading space) for the column, descending if its name starts with-, or an empty string if it is empty; the name is not quoted or escaped.Returns the strategy that picks each column's Java type from its SQL type (defaults toJdbcValueReader.OPINIONATED).Indicates if the database accepts catalog names in data manipulation statements; null untilloadCatalogAndSchemas()runs.Indicates if the database accepts catalog names in privilege definition statements; null untilloadCatalogAndSchemas()runs.Indicates if the database accepts catalog names in table definition statements; null untilloadCatalogAndSchemas()runs.Returns the first table with the given name, ignoring case and schema, or null if none matches.Returns the table with the given schema and name, ignoring case, or null; a null schema matches only tables without one.Returns the table with the given catalog, schema and name, ignoring case, or null; a null or empty catalog never matches.Returns a list of of tables sorted alphabetically.Returns a list of of tables sorted alphabetically, but with dependencies first.getUrl()booleanIndicates if each table's catalog is passed to the column, key and index metadata lookups instead of null (default is false).Replaces the catalog names and schemas with those reported by the database and records its catalog support flags.Runs each query with its parameters' example values and replaces its columns with those of the result.Loads the tables matching name pattern%in any catalog and schema, with their columns, keys and indexes, replacing those loaded before.loadTables(LoadTablesRequest request) Loads the tables and details selected by the request, replacing those loaded before and notifying thelistenerat each step.loadTables(String catalog, String schemaPattern, String tableNamePattern, String... types) Loads the tables matching the givenDatabaseMetaData.getTablesarguments, with their columns, keys and indexes, replacing those loaded before.setConnectionFactory(JdbcConnectionFactory connectionFactory) Sets a factorycreateConnection()uses in place of the driver, URL, credentials and properties; null removes it.setDriverClassName(String driverClassName) setEncodedPassword(String password) Sets the password already encoded with thepassword encoder.setJavaTypeOverride(String databaseTypeName, Class<?> javaType) Uses the given Java type for table and query columns of this database type name instead of themapper's choice.setListener(JdbcConnectionListener listener) Sets the listener notified asloadTables(LoadTablesRequest)progresses; null installs a no-op listener.setPasswordEncoder(Encoder<String, String> passwordEncoder) Sets the encoder used to store the password (defaults toEncoder.HEX); null stores it as plain text.setPlainTextPassword(String password) Encodes the password with thepassword encoderand stores it.setSqlToJavaTypeMapper(JdbcValueReader sqlToJavaTypeMapper) Sets the strategy that picks each column's Java type from its SQL type; null restoresJdbcValueReader.OPINIONATED.setUseCatalog(boolean useCatalog) Indicates if each table's catalog is passed to the column, key and index metadata lookups instead of null (default is false).setUsername(String username) toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.Methods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
addExceptionProperties, assertValid, assertValid, clone, exception, exception, exception, getInternalId, getInternalName, resetInternalIdMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionPropertiesMethods inherited from interface com.northconcepts.datapipeline.jdbc.JdbcConnectionFactory
close, closeConnectionMethods inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
fromJson, fromJson, toJson, toJson, toJsonMethods inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
fromXml, fromXml, fromXmlElement, toXml, toXml, toXml, toXml, toXml, toXmlElement
-
Constructor Details
-
JdbcConnection
public JdbcConnection()
-
-
Method Details
-
getListener
Returns the listener notified asloadTables(LoadTablesRequest)progresses; never null. -
setListener
Sets the listener notified asloadTables(LoadTablesRequest)progresses; null installs a no-op listener. -
getName
-
setName
-
getConnectionFactory
Returns the factorycreateConnection()uses in place of the driver, URL, credentials and properties, or null. -
setConnectionFactory
Sets a factorycreateConnection()uses in place of the driver, URL, credentials and properties; null removes it. -
getDriverClassName
-
setDriverClassName
-
getUrl
-
setUrl
-
getUsername
-
setUsername
-
getEncodedPassword
Returns the password as encoded by thepassword encoder(hex by default). -
setEncodedPassword
Sets the password already encoded with thepassword encoder. -
getPlainTextPassword
Returns the password decoded with thepassword encoder. -
setPlainTextPassword
Encodes the password with thepassword encoderand stores it. -
setPasswordEncoder
Sets the encoder used to store the password (defaults toEncoder.HEX); null stores it as plain text. An already stored password is not re-encoded, so set the encoder first. -
getPasswordEncoder
Returns the encoder used to store the password (defaults toEncoder.HEX). -
isUseCatalog
public boolean isUseCatalog()Indicates if each table's catalog is passed to the column, key and index metadata lookups instead of null (default is false). -
setUseCatalog
Indicates if each table's catalog is passed to the column, key and index metadata lookups instead of null (default is false). -
getProperties
Returns the extra properties passed to the JDBC driver bycreateConnection(). -
addProperty
Adds a property passed to the JDBC driver bycreateConnection(). -
addProperty
Adds a property passed to the JDBC driver bycreateConnection(). -
getTable
Returns the first table with the given name, ignoring case and schema, or null if none matches. -
getTable
Returns the table with the given schema and name, ignoring case, or null; a null schema matches only tables without one. -
getTable
Returns the table with the given catalog, schema and name, ignoring case, or null; a null or empty catalog never matches. -
getTables
-
getTablesSorted
Returns a list of of tables sorted alphabetically. -
getTablesSortedTopologically
Returns a list of of tables sorted alphabetically, but with dependencies first. If table A depends on table B, table B will be placed above table A in the returned list. -
addTable
Adds the table and sets this as its connection. -
getQueries
-
addQuery
Adds the query and sets this as its connection. -
addQuery
Adds a named SQL query;loadQueries()reads its result columns. -
getJavaTypeOverrides
-
setJavaTypeOverride
Uses the given Java type for table and query columns of this database type name instead of themapper's choice. -
getJavaTypeOverride
Returns the Java type override for the database type name, ignoring case, or null if there is none. -
getSqlToJavaTypeMapper
Returns the strategy that picks each column's Java type from its SQL type (defaults toJdbcValueReader.OPINIONATED). -
setSqlToJavaTypeMapper
Sets the strategy that picks each column's Java type from its SQL type; null restoresJdbcValueReader.OPINIONATED. -
getIsCatalogAtStart
Indicates if the catalog appears at the start of a qualified table name; null untilloadCatalogAndSchemas()runs. -
getSupportsCatalogsInDataManipulation
Indicates if the database accepts catalog names in data manipulation statements; null untilloadCatalogAndSchemas()runs. -
getSupportsCatalogsInTableDefinitions
Indicates if the database accepts catalog names in table definition statements; null untilloadCatalogAndSchemas()runs. -
getSupportsCatalogsInPrivilegeDefinitions
Indicates if the database accepts catalog names in privilege definition statements; null untilloadCatalogAndSchemas()runs. -
getCatalogNames
Returns the database's catalog names, as filled byloadCatalogAndSchemas(). -
addSchema
-
getSchemas
Returns the database's schemas, as filled byloadCatalogAndSchemas(). -
createConnection
Description copied from interface:JdbcConnectionFactoryReturns a connection to use; factories fromJdbcConnectionFactory.wrap(Connection)return the same connection on every call.- Specified by:
createConnectionin interfaceJdbcConnectionFactory
-
loadTables
Loads the tables matching name pattern%in any catalog and schema, with their columns, keys and indexes, replacing those loaded before. -
loadTables
public JdbcConnection loadTables(String catalog, String schemaPattern, String tableNamePattern, String... types) Loads the tables matching the givenDatabaseMetaData.getTablesarguments, with their columns, keys and indexes, replacing those loaded before. -
loadTables
Loads the tables and details selected by the request, replacing those loaded before and notifying thelistenerat each step. -
loadQueries
Runs each query with its parameters' example values and replaces its columns with those of the result. -
getQueryColumns
public static List<JdbcQueryColumn> getQueryColumns(ResultSetMetaData resultSetMetaData, JdbcConnection jdbcConnection) Describes each result column, choosing its Java type from the connection's type overrides or SQL-to-Java type mapper. -
getSqlOrderBy
Returns an ORDER BY clause (with a leading space) for the column, descending if its name starts with-, or an empty string if it is empty; the name is not quoted or escaped. -
loadCatalogAndSchemas
Replaces the catalog names and schemas with those reported by the database and records its catalog support flags. -
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable- Overrides:
toRecordin classBean
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Overrides:
fromRecordin classBean- Parameters:
source-- Returns:
- this instance.
-