Class JdbcDataset
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,Closeable,Serializable,AutoCloseable,Iterable<Record>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of supported database providers for JDBC datasets.Nested classes/interfaces inherited from class com.northconcepts.datapipeline.foundations.pipeline.dataset.Dataset
Dataset.ColumnsDataReader -
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 -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this object's current state to aDataException.protected voidCalled during the data loading process after all the column stats have been loaded.protected voidCalled at the end of the data loading process after all the records and column stats have been loaded.protected voidCalled at the start of the data loading process, but before any records or column stats have been loaded.voidclose()static JdbcDatasetcreateDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix, AbstractPipeline pipeline) Creates a persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.static JdbcDatasetcreateDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix, DataReaderFactory dataReaderFactory) Creates a persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.protected DataWriterWrites records to this dataset's cache after clearing it.getColumn(int index) Returns the column with the given name or null if there is none.longGets the name of the data table in the database.protected ColumngetOrCreateColumn(String name, int index) Returns the named column, creating it with the given 0-based field index if needed; called while collecting column stats.getRecord(long index) Returns the loaded record at the given 0-based index.longReturns the number of records loaded into this dataset so far.getRecordList(long offset, int count) Get a subset of the records cached in this dataset.Gets the name of the statistics table in the database.booleanReturns whether the database connection will be automatically closed when this dataset is closed.booleanReturns whether the database tables will be dropped when this dataset is closed.static JdbcDatasetopenDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix) Loads an existing persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.setAutoCloseConnection(boolean autoCloseConnection) Sets whether to automatically close the database connection when this dataset is closed.setDropTablesOnClose(boolean dropTablesOnClose) Sets whether to drop the database tables when this dataset is closed.Methods inherited from class com.northconcepts.datapipeline.foundations.pipeline.dataset.Dataset
addField, afterRecordsLoaded, cancelLoad, createColumnsDataReader, createDataReader, createDataReader, finalize, forEach, fromRecord, getColumnStatsException, getColumnStatsReaderThreads, getDataLoadException, getJob, getJobExecutor, getMaxColumnStatsRecords, getMaxColumnsToAnalyze, getMaxRecordsToLoad, getPipeline, isCollectUniqueValues, isColumnStatsLoaded, isDataLoaded, isDataLoading, isDetectBigNumberValues, isDetectBooleanValues, isDetectNumericValues, isDetectTemporalValues, isDetectUuidValues, isInferStringTypes, isRecordsLoaded, iterator, load, load, load, setCollectUniqueValues, setColumnStatsLoaded, setColumnStatsReaderThreads, setDetectBigNumberValues, setDetectBooleanValues, setDetectNumericValues, setDetectTemporalValues, setDetectUuidValues, setInferStringTypes, setJobExecutor, setMaxColumnStatsRecords, setMaxColumnsToAnalyze, setPipeline, setRecordsLoaded, stream, toRecord, updateColumns, waitForColumnStatsToLoad, waitForColumnStatsToLoad, waitForRecordsToLoad, waitForRecordsToLoad, waitUntilJobFinishedMethods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
assertValid, assertValid, clone, exception, exception, exception, getInternalId, getInternalName, resetInternalIdMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionPropertiesMethods inherited from interface java.lang.Iterable
spliteratorMethods 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
-
Method Details
-
createDataset
public static JdbcDataset createDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix, AbstractPipeline pipeline) Creates a persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.The data and statistics tables will remain on the database even after the dataset is closed, unless
setDropTablesOnClose(boolean)is set totrue.- Parameters:
databaseProvider- the database provider defining database-specific SQL syntaxfactory- the JDBC connection factory for creating database connectionstableNamePrefix- the prefix for the data and statistics table namespipeline- the pipeline to use for loading data into the dataset- Returns:
- a new
JdbcDatasetinstance
-
createDataset
public static JdbcDataset createDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix, DataReaderFactory dataReaderFactory) Creates a persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.The data and statistics tables will remain on the database even after the dataset is closed, unless
setDropTablesOnClose(boolean)is set totrue.- Parameters:
databaseProvider- the database provider defining database-specific SQL syntaxfactory- the JDBC connection factory for creating database connectionstableNamePrefix- the prefix for the data and statistics table namesdataReaderFactory- the factory for creating the data reader to populate the dataset- Returns:
- a new
JdbcDatasetinstance
-
openDataset
public static JdbcDataset openDataset(JdbcDataset.DatabaseProvider databaseProvider, JdbcConnectionFactory factory, String tableNamePrefix) Loads an existing persistent dataset stored in a database determined by the providedJdbcDataset.DatabaseProvider.This method opens a dataset that was previously created with
createDataset(com.northconcepts.datapipeline.foundations.pipeline.dataset.JdbcDataset.DatabaseProvider, com.northconcepts.datapipeline.jdbc.JdbcConnectionFactory, java.lang.String, com.northconcepts.datapipeline.foundations.pipeline.AbstractPipeline)and reads the existing data and statistics from the database tables.- Parameters:
databaseProvider- the database provider defining database-specific SQL syntaxfactory- the JDBC connection factory for creating database connectionstableNamePrefix- the prefix for the data and statistics table names- Returns:
- a
JdbcDatasetinstance containing the existing dataset
-
getDataTableName
Gets the name of the data table in the database.- Returns:
- the data table name
-
getStatsTableName
Gets the name of the statistics table in the database.- Returns:
- the statistics table name
-
setDropTablesOnClose
Sets whether to drop the database tables when this dataset is closed.If
true, both the data and statistics tables will be dropped from the database whenclose()is called. Iffalse(default), the tables will remain in the database.- Parameters:
dropTablesOnClose-trueto drop tables on close,falseotherwise- Returns:
- this instance for method chaining
-
isDropTablesOnClose
public boolean isDropTablesOnClose()Returns whether the database tables will be dropped when this dataset is closed.- Returns:
trueif tables will be dropped on close,falseotherwise
-
setAutoCloseConnection
Sets whether to automatically close the database connection when this dataset is closed.If
true(default), the database connection will be closed whenclose()is called. Iffalse, the connection will remain open and must be closed manually.- Parameters:
autoCloseConnection-trueto auto-close the connection,falseotherwise- Returns:
- this instance for method chaining
-
isAutoCloseConnection
public boolean isAutoCloseConnection()Returns whether the database connection will be automatically closed when this dataset is closed.- Returns:
trueif the connection will be auto-closed,falseotherwise
-
close
public void close() -
getRecordCount
public long getRecordCount()Description copied from class:DatasetReturns the number of records loaded into this dataset so far.- Specified by:
getRecordCountin classDataset
-
getRecord
Description copied from class:DatasetReturns the loaded record at the given 0-based index. -
getRecordList
Description copied from class:DatasetGet a subset of the records cached in this dataset.- Overrides:
getRecordListin classDataset
-
getColumnCount
public long getColumnCount()- Specified by:
getColumnCountin classDataset
-
getColumnNames
- Specified by:
getColumnNamesin classDataset
-
getColumn
-
getColumn
Description copied from class:DatasetReturns the column with the given name or null if there is none. -
getOrCreateColumn
Description copied from class:DatasetReturns the named column, creating it with the given 0-based field index if needed; called while collecting column stats.- Specified by:
getOrCreateColumnin classDataset
-
getColumns
- Specified by:
getColumnsin classDataset
-
beforeLoad
protected void beforeLoad()Description copied from class:DatasetCalled at the start of the data loading process, but before any records or column stats have been loaded.- Specified by:
beforeLoadin classDataset
-
afterLoad
protected void afterLoad()Description copied from class:DatasetCalled at the end of the data loading process after all the records and column stats have been loaded. -
afterColumnStatsLoaded
protected void afterColumnStatsLoaded()Description copied from class:DatasetCalled during the data loading process after all the column stats have been loaded. The records would have already been loaded when this method is called since column stats require additional processing.- Overrides:
afterColumnStatsLoadedin classDataset
-
createDataWriter
Description copied from class:DatasetWrites records to this dataset's cache after clearing it.- Specified by:
createDataWriterin classDataset
-
addExceptionProperties
Description copied from class:FoundationObjectAdds this object's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Specified by:
addExceptionPropertiesin interfaceDataExceptionContributor- Overrides:
addExceptionPropertiesin classFoundationObject
-