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

Modifier and Type
Method
Description
`void`
`addDriver(org.h2gis.api.DriverFunction driver)`
`static String`
`exportToDataBase(Connection sourceConnection, String sourceTable, Connection targetConnection, String targetTable, int mode, int batch_size)`
Method to export a table into another database
`String[]`
`exportToFile(Connection connection, String tableName, String filePath, String encoding, boolean deleteFile)`
Export a table to a file
`List<String>`
`getAllExportDriverSupportedExtensions()`
`List<String>`
`getAllImportDriverSupportedExtensions()`
`List<org.h2gis.api.DriverFunction>`
`getDriverFunctionList()`
`org.h2gis.api.DriverFunction`
`getExportDriverFromFile(File file)`
`org.h2gis.api.DriverFunction`
`getImportDriverFromFile(File file)`
`String[]`
`importFile(Connection connection, String filePath, String tableName, String encoding, boolean deleteTable)`
Import a file to a database
`static String`
`linkedFile(Connection connection, String filePath, String tableName, boolean delete)`
Create a dynamic link from a file to a H2GIS database
`static String`
`linkedTable(Connection targetConnection, Map<String,String> databaseProperties, String sourceTable, String targetTable, boolean delete)`
Link a table from another database to an H2GIS database
`static String`
`linkedTable(Connection targetConnection, Map<String,String> databaseProperties, String sourceTable, String targetTable, boolean delete, int fetchSize)`
Link a table from another database to an H2GIS database
`static String`
`linkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete)`
Link a table from another database to an H2GIS database
`static String`
`linkedTable(Connection targetConnection, Properties properties, String sourceTable, String targetTable, boolean delete, int fetchSize)`
Link a table from another database to an H2GIS database
`void`
`removeDriver(org.h2gis.api.DriverFunction driver)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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 table
  `properties` - External database database properties to set up a connection to the target database
  `sourceTable` - The name of the table in the external database
  `targetTable` - The name of the table in the H2GIS database
  `delete` - 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 database
  `sourceTable` - The name of the table in the external database
  `targetTable` - The name of the table in the H2GIS database
  `delete` - True to delete the table if exists
  `fetchSize` - 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 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 database
  `sourceTable` - The name of the table in the external database
  `targetTable` - The name of the table in the H2GIS database
  `delete` - 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 SQLException
Link a table from another database to an H2GIS database

Parameters:
  `targetConnection` - The targetConnection to the database that will received the table
  `databaseProperties` - External database databaseProperties to set up a connection to the target database
  `sourceTable` - The name of the table in the external database
  `targetTable` - The name of the table in the H2GIS database
  `delete` - True to delete the table if exists
  `fetchSize` - 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 database
  `filePath` - The path of the file
  `tableName` - The name of the table created to store the file
  `delete` - 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 connection
  `sourceTable` - the name of the table to export or a select query
  `targetConnection` - target database connection
  `targetTable` - target table name
  `mode` - -1 delete the target table if exists and create a new table, 0 create a new table, 1 update the target table if exists
  `batch_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 database
  `tableName` - Name of the table to save.
  `filePath` - Path of the destination file.
  `encoding` - Encoding of the file. Can be null
  `deleteFile` - 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 database
  `filePath` - The path of the file
  `tableName` - The name of the table created to store the file
  `encoding` - An encoding value to read the file. Can be null
  `deleteTable` - True to delete the table if exists
Returns:
  the name of table imported and formated according the database rules
Throws:
  `SQLException`