Package org.h2gis.functions.io.utility
Class IOMethods
- java.lang.Object
-
- org.h2gis.functions.io.utility.IOMethods
-
public class IOMethods extends Object
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
Constructors Constructor Description IOMethods()Create a new instance of IOMethods in order to be able to use custom file drivers Add built-in supported drivers
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDriver(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<String>getAllExportDriverSupportedExtensions()List<String>getAllImportDriverSupportedExtensions()List<org.h2gis.api.DriverFunction>getDriverFunctionList()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)
-
-
-
Method Detail
-
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 name of the linked table
- Throws:
SQLException
-
linkedTable
public static String linkedTable(Connection targetConnection, Map<String,String> databaseProperties, 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 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 name of the linked table
- Throws:
SQLException
-
linkedTable
public static String linkedTable(Connection targetConnection, Map<String,String> databaseProperties, 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 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
public List<org.h2gis.api.DriverFunction> 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
public List<String> getAllExportDriverSupportedExtensions()
- Returns:
- Collect all supported file extensions
-
getAllImportDriverSupportedExtensions
public List<String> getAllImportDriverSupportedExtensions()
- Returns:
- Collect all supported file extensions
-
getExportDriverFromFile
public org.h2gis.api.DriverFunction getExportDriverFromFile(File file)
- Parameters:
file- File path- Returns:
- First compatible driver
-
getImportDriverFromFile
public org.h2gis.api.DriverFunction getImportDriverFromFile(File file)
- 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
-
-