Package org.h2gis.functions.io.utility
Class IOMethods
java.lang.Object
org.h2gis.functions.io.utility.IOMethods
Utility methods to :
- import, export a file in a database (H2GIS, POSTGIS)
- export a table from another database (H2GIS, POSTGIS)
- link a file or table (H2GIS only)
- Author:
- Erwan Bocher, CNRS, 2020, Sylvain PALOMINOS (UBS 2019), Nicolas Fortin (Univ. Gustave Eiffel 2020)
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of IOMethods in order to be able to use custom file drivers Add built-in supported drivers -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDriver(org.h2gis.api.DriverFunction driver) static StringexportToDataBase(Connection sourceConnection, String sourceTable, Connection targetConnection, String targetTable, int mode, int batch_size) Method to export a table into another databaseString[]exportToFile(Connection connection, String tableName, String filePath, String encoding, boolean deleteFile) Export a table to a fileList<org.h2gis.api.DriverFunction>org.h2gis.api.DriverFunctiongetExportDriverFromFile(File file) org.h2gis.api.DriverFunctiongetImportDriverFromFile(File file) String[]importFile(Connection connection, String filePath, String tableName, String encoding, boolean deleteTable) Import a file to a databasestatic StringlinkedFile(Connection connection, String filePath, String tableName, boolean delete) Create a dynamic link from a file to a H2GIS databasestatic StringlinkedTable(Connection targetConnection, Map<String, String> databaseProperties, String sourceTable, String targetTable, boolean delete) Link a table from another database to an H2GIS databasestatic StringlinkedTable(Connection targetConnection, Map<String, String> databaseProperties, String sourceTable, String targetTable, boolean delete, int fetchSize) Link a table from another database to an H2GIS databasestatic StringlinkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete) Link a table from another database to an H2GIS databasestatic StringlinkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete, int fetchSize) Link a table from another database to an H2GIS databasevoidremoveDriver(org.h2gis.api.DriverFunction driver)
-
Constructor Details
-
IOMethods
public IOMethods()Create a new instance of IOMethods in order to be able to use custom file drivers Add built-in supported drivers
-
-
Method Details
-
linkedTable
public static String linkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete) throws SQLException Link a table from another database to an H2GIS database- Parameters:
targetConnection- The targetConnection to the database that will received the tableproperties- External database database properties to set up a connection to the target databasesourceTable- The name of the table in the external databasetargetTable- The name of the table in the H2GIS databasedelete- True to delete the table if exists- Returns:
- the name of the linked table
- Throws:
SQLException
-
linkedTable
public static String linkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete, int fetchSize) throws SQLException Link a table from another database to an H2GIS database- Parameters:
targetConnection- The targetConnection to the database that will received the table a connection to the target databasesourceTable- The name of the table in the external databasetargetTable- The name of the table in the H2GIS databasedelete- True to delete the table if existsfetchSize- The number of rows fetched from the linked table- Returns:
- The absolute path of the exported files
- Throws:
SQLException
-
linkedTable
public static String linkedTable(Connection targetConnection, Map<String, String> databaseProperties, String sourceTable, String targetTable, boolean delete) throws SQLExceptionLink a table from another database to an H2GIS database- Parameters:
targetConnection- The targetConnection to the database that will received the table a connection to the target databasesourceTable- The name of the table in the external databasetargetTable- The name of the table in the H2GIS databasedelete- True to delete the table if exists- Returns:
- The absolute path of the exported files
- Throws:
SQLException
-
linkedTable
public static String linkedTable(Connection targetConnection, Map<String, String> databaseProperties, String sourceTable, String targetTable, boolean delete, int fetchSize) throws SQLExceptionLink a table from another database to an H2GIS database- Parameters:
targetConnection- The targetConnection to the database that will received the tabledatabaseProperties- External database databaseProperties to set up a connection to the target databasesourceTable- The name of the table in the external databasetargetTable- The name of the table in the H2GIS databasedelete- True to delete the table if existsfetchSize- The number of rows fetched from the linked table- Returns:
- the name of the linked table
- Throws:
SQLException
-
linkedFile
public static String linkedFile(Connection connection, String filePath, String tableName, boolean delete) throws SQLException Create a dynamic link from a file to a H2GIS database- Parameters:
connection- The connection to databasefilePath- The path of the filetableName- The name of the table created to store the filedelete- True to delete the table if exists- Throws:
SQLException
-
exportToDataBase
public static String exportToDataBase(Connection sourceConnection, String sourceTable, Connection targetConnection, String targetTable, int mode, int batch_size) throws SQLException Method to export a table into another database- Parameters:
sourceConnection- source database connectionsourceTable- the name of the table to export or a select querytargetConnection- target database connectiontargetTable- target table namemode- -1 delete the target table if exists and create a new table, 0 create a new table, 1 update the target table if existsbatch_size- batch size value before sending the data- Returns:
- name of the export table formatted according the database target
- Throws:
SQLException
-
getDriverFunctionList
- Returns:
- Current list of supported drivers
-
addDriver
public void addDriver(org.h2gis.api.DriverFunction driver) - Parameters:
driver- Driver to add to supported file drivers
-
removeDriver
public void removeDriver(org.h2gis.api.DriverFunction driver) - Parameters:
driver- Driver to remove from the list of supported drivers
-
getAllExportDriverSupportedExtensions
- Returns:
- Collect all supported file extensions
-
getAllImportDriverSupportedExtensions
- Returns:
- Collect all supported file extensions
-
getExportDriverFromFile
- Parameters:
file- File path- Returns:
- First compatible driver
-
getImportDriverFromFile
- Parameters:
file- File path- Returns:
- First compatible driver
-
exportToFile
public String[] exportToFile(Connection connection, String tableName, String filePath, String encoding, boolean deleteFile) throws SQLException Export a table to a file- Parameters:
connection- The connection to databasetableName- Name of the table to save.filePath- Path of the destination file.encoding- Encoding of the file. Can be nulldeleteFile- true to delete the file if exists- Returns:
- The absolute path of the exported files
- Throws:
SQLException
-
importFile
public String[] importFile(Connection connection, String filePath, String tableName, String encoding, boolean deleteTable) throws SQLException Import a file to a database- Parameters:
connection- The connection to databasefilePath- The path of the filetableName- The name of the table created to store the fileencoding- An encoding value to read the file. Can be nulldeleteTable- True to delete the table if exists- Returns:
- the name of table imported and formated according the database rules
- Throws:
SQLException
-