Class DataSourceTools
- All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable
DataSourceTools provides a number of static utility methods for generating DataSource information from other metadata (database tables, Hibernate mappings and Reflection on existing Java classes)-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classResult object forcopyRecords(String, String, CopyOptions).static final classResult object forexportRecordsToFile(DataSource, ExportOptions).static enumOutput format for exportDataSourceToFile(DataSource, ExportFormat, ExportOptions).static final classOptions for exportDataSourceToFile(DataSource, ExportOptions).static final classResult object for stream-basedexportRecords(java.lang.String, java.io.Writer, com.isomorphic.tools.DataSourceTools.ExportFormat, java.lang.String, java.lang.Integer, java.lang.Integer)operations. -
Method Summary
Modifier and TypeMethodDescriptioncopyRecords(DataSource sourceDS, DataSource targetDS, com.isomorphic.tools.DataSourceTools.CopyOptions options) Copies records from a source DataSource to a target DataSource.copyRecords(String sourceDS, String targetDS, com.isomorphic.tools.DataSourceTools.CopyOptions options) Copies records from a source DataSource to a target DataSource.exportRecords(DataSource ds, Writer writer, DataSourceTools.ExportFormat format, String recordTag, Integer maxRows, Integer pageSize) Exports records from a DataSource to a Writer in the specified format.exportRecords(String dsId, Writer writer, DataSourceTools.ExportFormat format, String recordTag, Integer maxRows, Integer pageSize) Exports records from a DataSource to a Writer in the specified format.exportRecordsToFile(DataSource ds, DataSourceTools.ExportOptions options) Exports the given DataSource to a single output file under webRoot by paging through fetch().exportRecordsToFile(String dsId, DataSourceTools.ExportOptions options) Loads a DataSource by ID and exports it to disk under webRoot.static MapgetDataSourceConfigFromHibernateMapping(String entityName) Returns the DataSource configuration map derived from the given Hibernate mappingstatic ObjectgetDataSourceConfigFromJavaClass(String className) Returns the DataSource configuration map derived by applying Reflection to the given Java classstatic MapgetDataSourceConfigFromJPAClass(String className) Returns the DataSource configuration map derived from the given JPA-mapped classstatic MapgetDataSourceConfigFromTable(String tableName, String schema, String serverType, String dbName, String timestampType, boolean returnSQLTypes) Returns the DataSource configuration map derived from the given database table
-
Method Details
-
getDataSourceConfigFromTable
public static Map getDataSourceConfigFromTable(String tableName, String schema, String serverType, String dbName, String timestampType, boolean returnSQLTypes) throws Exception Returns the DataSource configuration map derived from the given database table- Parameters:
tableName- the name of the tableschema- the name of the database schema. Some databases require this, others do not; indeed, some do not recognize the conceptserverType- "sql" or "hibernate", how to obtain a database connectiondbName- For "sql" types only, the database to connect totimestampType- The SmartClient field type to use when mapping SQL columns of type TIMESTAMP. Must be "date", "datetime" or "time"; defaults to "datetime".- Returns:
- The DataSource configuration map, or null if the configuration could not be derived (for example, because the table did not exist)
- Throws:
Exception
-
getDataSourceConfigFromHibernateMapping
Returns the DataSource configuration map derived from the given Hibernate mapping- Parameters:
entityName- the "entity-name" of the Hibernate mapping- Returns:
- The DataSource configuration map, or null if the given entity name was not found
- Throws:
Exception
-
getDataSourceConfigFromJPAClass
Returns the DataSource configuration map derived from the given JPA-mapped class- Parameters:
className- the name of JPA-mapped class- Returns:
- The DataSource configuration map, or null if the given class name was not found
- Throws:
Exception
-
getDataSourceConfigFromJavaClass
Returns the DataSource configuration map derived by applying Reflection to the given Java class- Parameters:
className- the fully-qualified class name (eg, com.somecompany.SomeClass)- Returns:
- The DataSource configuration map, or null if the given class was not found
- Throws:
Exception
-
copyRecords
public static DataSourceTools.CopyDataSourceResult copyRecords(String sourceDS, String targetDS, com.isomorphic.tools.DataSourceTools.CopyOptions options) throws Exception Copies records from a source DataSource to a target DataSource.Fetches all records from the source DataSource and adds them to the target DataSource. Fields in the source records that are not present in the target DataSource are filtered out.
- Parameters:
sourceDS- Name of the source DataSourcetargetDS- Name of the target DataSourceoptions- Copy options including pageSize, transactionMode, stopOnError, and streamResults- Returns:
- Result of the copy operation, including stats and any failures
- Throws:
Exception- if either DataSource cannot be loaded or other errors occur
-
copyRecords
public static DataSourceTools.CopyDataSourceResult copyRecords(DataSource sourceDS, DataSource targetDS, com.isomorphic.tools.DataSourceTools.CopyOptions options) throws Exception Copies records from a source DataSource to a target DataSource.Fetches all records from the source DataSource and adds them to the target DataSource. Fields in the source records that are not present in the target DataSource are filtered out.
- Parameters:
sourceDS- instance of source DataSourcetargetDS- instance of target DataSourceoptions- Copy options including pageSize, transactionMode, stopOnError, and streamResults- Returns:
- Result of the copy operation, including stats and any failures
- Throws:
Exception- if either DataSource cannot be loaded or other errors occur
-
exportRecords
public static DataSourceTools.ExportRecordsResult exportRecords(String dsId, Writer writer, DataSourceTools.ExportFormat format, String recordTag, Integer maxRows, Integer pageSize) throws Exception Exports records from a DataSource to a Writer in the specified format.This is the core export method that writes to any Writer (HTTP response, file, string, etc.). Use
exportRecordsToFile(java.lang.String, com.isomorphic.tools.DataSourceTools.ExportOptions)for filesystem-based export.- Parameters:
dsId- DataSource IDwriter- Writer to write records to (JSON or XML)format- Export format (JSON or XML)recordTag- XML record tag name (ignored for JSON, can be null)maxRows- Maximum number of rows to export (null = all rows)pageSize- Fetch page size (null = default 500)- Returns:
- Export result with statistics
- Throws:
Exception- if DataSource not found or export fails
-
exportRecords
public static DataSourceTools.ExportRecordsResult exportRecords(DataSource ds, Writer writer, DataSourceTools.ExportFormat format, String recordTag, Integer maxRows, Integer pageSize) throws Exception Exports records from a DataSource to a Writer in the specified format.This is the core export method that writes to any Writer (HTTP response, file, string, etc.). Use
exportRecordsToFile(java.lang.String, com.isomorphic.tools.DataSourceTools.ExportOptions)for filesystem-based export.- Parameters:
ds- DataSource instancewriter- Writer to write records to (JSON or XML)format- Export format (JSON or XML)recordTag- XML record tag name (ignored for JSON, can be null)maxRows- Maximum number of rows to export (null = all rows)pageSize- Fetch page size (null = default 500)- Returns:
- Export result with statistics
- Throws:
Exception- if export fails
-
exportRecordsToFile
public static DataSourceTools.ExportDataSourceResult exportRecordsToFile(String dsId, DataSourceTools.ExportOptions options) throws Exception Loads a DataSource by ID and exports it to disk under webRoot.- Throws:
Exception
-
exportRecordsToFile
public static DataSourceTools.ExportDataSourceResult exportRecordsToFile(DataSource ds, DataSourceTools.ExportOptions options) throws Exception Exports the given DataSource to a single output file under webRoot by paging through fetch().This is a filesystem-writing API. Use
exportRecords(java.lang.String, java.io.Writer, com.isomorphic.tools.DataSourceTools.ExportFormat, java.lang.String, java.lang.Integer, java.lang.Integer)to write to any Writer/OutputStream.- Throws:
Exception
-