Skip to content

Commit

Permalink
dbeaver/pro#1900 tasks virtual fs (#2040)
Browse files Browse the repository at this point in the history
* dbeaver/pro#1900 Refactor DT and general UI

* dbeaver/pro#1900 Export to external FS implementation
  • Loading branch information
serge-rider authored Oct 12, 2023
1 parent bd9a18b commit d0a820d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCExcep
// Remove extension property (we specify file name directly)
properties.remove(StreamConsumerSettings.PROP_FILE_EXTENSION);

consumer.initTransfer(
dataContainer,
settings,
new IDataTransferConsumer.TransferParameters(processor.isBinaryFormat(), processor.isHTMLFormat()),
exporter,
properties);

DatabaseTransferProducer producer = new DatabaseTransferProducer(
dataContainer,
Expand All @@ -261,6 +255,14 @@ public void fetchRow(DBCSession session, DBCResultSet resultSet) throws DBCExcep
producerSettings.setQueryRowCount(false);
producerSettings.setOpenNewConnections(CommonUtils.getOption(parameters.getDbProducerSettings(), "openNewConnection"));

consumer.initTransfer(
dataContainer,
settings,
new IDataTransferConsumer.TransferParameters(processor.isBinaryFormat(), processor.isHTMLFormat()),
exporter,
properties,
producer.getProject());

producer.transferData(monitor, consumer, null, producerSettings, null);

consumer.finishTransfer(monitor, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String[] getAvailableFileSystems(@NotNull WebSession webSession, @NotNull
public FSFile getFile(@NotNull WebSession webSession, @NotNull String projectId, @NotNull URI fileUri)
throws DBWebException {
try {
Path filePath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fileUri);
Path filePath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fileUri);
return new FSFile(filePath);
} catch (Exception e) {
throw new DBWebException("Failed to found file: " + e.getMessage(), e);
Expand All @@ -65,7 +65,7 @@ public FSFile getFile(@NotNull WebSession webSession, @NotNull String projectId,
public FSFile[] getFiles(@NotNull WebSession webSession, @NotNull String projectId, @NotNull URI folderURI)
throws DBWebException {
try {
Path folderPath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), folderURI);
Path folderPath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), folderURI);
try (var filesStream = Files.list(folderPath)) {
return filesStream.map(FSFile::new)
.toArray(FSFile[]::new);
Expand All @@ -80,7 +80,7 @@ public FSFile[] getFiles(@NotNull WebSession webSession, @NotNull String project
public String readFileContent(@NotNull WebSession webSession, @NotNull String projectId, @NotNull URI fileUri)
throws DBWebException {
try {
Path filePath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fileUri);
Path filePath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fileUri);
return Files.readString(filePath);
} catch (Exception e) {
throw new DBWebException("Failed to read file content: " + e.getMessage(), e);
Expand All @@ -97,7 +97,7 @@ public boolean writeFileContent(
)
throws DBWebException {
try {
Path filePath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fileURI);
Path filePath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fileURI);
if (!forceOverwrite && Files.exists(filePath)) {
throw new DBException("Cannot overwrite exist file");
}
Expand All @@ -116,7 +116,7 @@ public FSFile createFile(
@NotNull URI fileUri
) throws DBWebException {
try {
Path filePath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fileUri);
Path filePath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fileUri);
Files.createFile(filePath);
return new FSFile(filePath);
} catch (Exception e) {
Expand All @@ -132,8 +132,8 @@ public FSFile moveFile(
@NotNull URI toURI
) throws DBWebException {
try {
Path from = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fromURI);
Path to = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), toURI);
Path from = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fromURI);
Path to = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), toURI);
Files.move(from, to);
return new FSFile(to);
} catch (Exception e) {
Expand All @@ -149,7 +149,7 @@ public FSFile createFolder(
@NotNull URI folderURI
) throws DBWebException {
try {
Path folderPath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), folderURI);
Path folderPath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), folderURI);
Files.createDirectory(folderPath);
return new FSFile(folderPath);
} catch (Exception e) {
Expand All @@ -164,7 +164,7 @@ public boolean deleteFile(
@NotNull URI fileUri
) throws DBWebException {
try {
Path filePath = webSession.getFileSystemManager(projectId).of(webSession.getProgressMonitor(), fileUri);
Path filePath = webSession.getFileSystemManager(projectId).getPathFromURI(webSession.getProgressMonitor(), fileUri);
Files.delete(filePath);
return true;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getId() {
}

@Override
public Path getPathByURI(DBRProgressMonitor monitor, URI uri) {
public Path getPathByURI(@NotNull DBRProgressMonitor monitor, @NotNull URI uri) {
return rmNioFileSystemProvider.getPath(uri);
}

Expand Down

0 comments on commit d0a820d

Please sign in to comment.