Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver signature + improvements #1085

Merged
merged 11 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions h2gis-api/src/main/java/org/h2gis/api/DriverFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,37 @@ enum IMPORT_DRIVER_TYPE {LINK, COPY}
*/
void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress)
throws SQLException, IOException;

/**
* Export the specified table from the specified connection into the specified file.
*
* @param connection Active connection, do not close this connection.
* @param tableReference [[catalog.]schema.]table reference.
* @param fileName File path to write, if exists it may be replaced.
* @param deleteFiles True to delete the files if exist
* @param progress Progress visitor following the execution.
* @throws SQLException Table read error.
* @throws IOException File write error.
*/
void exportTable(Connection connection, String tableReference, File fileName, boolean deleteFiles, ProgressVisitor progress)
throws SQLException, IOException;

/**
* Export the specified table from the specified connection into the specified file.
*
* @param connection Active connection, do not close this connection.
* @param tableReference [[catalog.]schema.]table reference.
* @param fileName File path to write, if exists it may be replaced.
* @param options Options to use for the export like encoding, separator ...
* The options are different from a format to another.
* @param deleteFiles True to delete the files if exist
* @param progress Progress visitor following the execution.
* @throws SQLException Table read error.
* @throws IOException File write error.
*/
void exportTable(Connection connection, String tableReference, File fileName,
String options,boolean deleteFiles,ProgressVisitor progress) throws SQLException, IOException;
ebocher marked this conversation as resolved.
Show resolved Hide resolved

/**
* Export the specified table from the specified connection into the specified file.
*
Expand All @@ -105,8 +135,8 @@ void exportTable(Connection connection, String tableReference, File fileName, Pr
* @throws SQLException Table read error.
* @throws IOException File write error.
*/
void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
String options) throws SQLException, IOException;
void exportTable(Connection connection, String tableReference, File fileName,
String options,ProgressVisitor progress) throws SQLException, IOException;
ebocher marked this conversation as resolved.
Show resolved Hide resolved

/**
* Import the specified file into the specified table in the specified connection.
Expand All @@ -127,26 +157,44 @@ void importFile(Connection connection, String tableReference, File fileName, Pro
* @param connection Active connection, do not close this connection.
* @param tableReference [[catalog.]schema.]table reference.
* @param fileName File path to read.
* @param progress Progress visitor following the execution.
* @param options Options to use for the export like encoding, separator ...
* The options are different from a format to another.
* @param progress Progress visitor following the execution.
* @throws SQLException Table write error.
* @throws IOException File read error.
*/
void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
String options) throws SQLException, IOException;
void importFile(Connection connection, String tableReference, File fileName, String options, ProgressVisitor progress)
throws SQLException, IOException;

/**
* Import the specified file into the specified table in the specified connection.
*
* @param connection Active connection, do not close this connection.
* @param tableReference [[catalog.]schema.]table reference.
* @param fileName File path to read.
* @param deleteTables True if the existing table used for the import should be deleted, false otherwise.
* @param progress Progress visitor following the execution.
* @throws SQLException Table write error.
* @throws IOException File read error.
*/
void importFile(Connection connection, String tableReference, File fileName, boolean deleteTables, ProgressVisitor progress
) throws SQLException, IOException;

/**
* Import the specified file into the specified table in the specified connection.
*
* @param connection Active connection, do not close this connection.
* @param tableReference [[catalog.]schema.]table reference.
* @param fileName File path to read.
* @param options Options to use for the export like encoding, separator ...
* The options are different from a format to another.
* @param deleteTables True if the existing table used for the import should be deleted, false otherwise.
* @param progress Progress visitor following the execution.
* @throws SQLException Table write error.
* @throws IOException File read error.
*/
void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
boolean deleteTables) throws SQLException, IOException;
void importFile(Connection connection, String tableReference, File fileName, String options, boolean deleteTables, ProgressVisitor progress
) throws SQLException, IOException;


}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,20 @@ public void exportTable(Connection connection, String tableReference, File fileN
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
String options) throws SQLException, IOException {
public void exportTable(Connection connection, String tableReference, File fileName, boolean deleteFiles, ProgressVisitor progress) throws SQLException, IOException {

throw new SQLFeatureNotSupportedException("Work in progress..");
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, String options, boolean deleteFiles, ProgressVisitor progress) throws SQLException, IOException {

throw new SQLFeatureNotSupportedException("Work in progress..");
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, String options, ProgressVisitor progress
) throws SQLException, IOException {
throw new SQLFeatureNotSupportedException("Work in progress..");
}

Expand Down Expand Up @@ -167,14 +179,19 @@ public void importFile(Connection connection, String tableReference, File fileNa
}

@Override
public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
String options) throws SQLException, IOException {
public void importFile(Connection connection, String tableReference, File fileName, String options, ProgressVisitor progress
) throws SQLException, IOException {
openFile(connection, fileName.getAbsolutePath(), tableReference);
}

@Override
public void importFile(Connection connection, String tableReference, File fileName,boolean deleteTables, ProgressVisitor progress
) throws SQLException, IOException {
openFile(connection, fileName.getAbsolutePath(), tableReference);
}

@Override
public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
boolean deleteTables) throws SQLException, IOException {
public void importFile(Connection connection, String tableReference, File fileName, String options, boolean deleteTables, ProgressVisitor progress) throws SQLException, IOException {
openFile(connection, fileName.getAbsolutePath(), tableReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,22 @@ public boolean isSpatialFormat(String extension) {

@Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException{
// Import only driver
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException{
// Import only driver
public void exportTable(Connection connection, String tableReference, File fileName, boolean deleteFiles, ProgressVisitor progress) throws SQLException, IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, String options, boolean deleteFiles, ProgressVisitor progress) throws SQLException, IOException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void exportTable(Connection connection, String tableReference, File fileName, String encoding,ProgressVisitor progress) throws SQLException, IOException{
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
Expand All @@ -96,29 +106,34 @@ public void importFile(Connection connection, String tableReference, File fileNa
if(prjFile.exists()) {
srid = PRJUtil.getSRID(prjFile);
}
try(FileInputStream fos = new FileInputStream(fileName)) {
ascReaderDriver.read(connection, fos, progress, tableReference, srid);
}
ascReaderDriver.read(connection, fileName, progress, tableReference, srid);

}

@Override
public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
String options) throws SQLException, IOException {
public void importFile(Connection connection, String tableReference, File fileName, String options, ProgressVisitor progress
) throws SQLException, IOException {
importFile(connection, tableReference, fileName, progress);
}

@Override
public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress,
boolean deleteTables) throws SQLException, IOException {

public void importFile(Connection connection, String tableReference, File fileName, boolean deleteTables, ProgressVisitor progress
) throws SQLException, IOException {
if(deleteTables) {
final boolean isH2 = JDBCUtilities.isH2DataBase(connection);
TableLocation requestedTable = TableLocation.parse(tableReference, isH2);
Statement stmt = connection.createStatement();
stmt.execute("DROP TABLE IF EXISTS " + requestedTable);
stmt.close();
}

importFile(connection, tableReference, fileName, progress);
}

@Override
public void importFile(Connection connection, String tableReference, File fileName, String encoding, boolean deleteTables, ProgressVisitor progress) throws SQLException, IOException {
AscReaderDriver ascReaderDriver = new AscReaderDriver();
ascReaderDriver.setDeleteTable(deleteTables);
ascReaderDriver.setEncoding(encoding);
importFile(connection, tableReference, fileName, progress, ascReaderDriver);
}
}
Loading