-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' into CB-3197-interface-comments
- Loading branch information
Showing
82 changed files
with
1,986 additions
and
863 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...r/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/fs/nio/RMByteArrayChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package io.cloudbeaver.model.rm.fs.nio; | ||
|
||
import org.jkiss.dbeaver.DBException; | ||
import org.jkiss.dbeaver.model.nio.ByteArrayChannel; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.OpenOption; | ||
import java.util.Set; | ||
|
||
// copy of jdk.nio.zipfs.ByteArrayChannel | ||
public class RMByteArrayChannel extends ByteArrayChannel { | ||
|
||
private final RMPath rmPath; | ||
|
||
public RMByteArrayChannel(byte[] buf, RMPath rmPath, Set<? extends OpenOption> options) { | ||
super(buf, options); | ||
this.rmPath = rmPath; | ||
} | ||
|
||
@Override | ||
protected void createNewFile() throws IOException { | ||
try { | ||
rmPath.getFileSystem().getRmController().createResource( | ||
rmPath.getRmProjectId(), rmPath.getResourcePath(), false | ||
); | ||
} catch (DBException e) { | ||
throw new IOException("Failed to create new file: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void writeToFile() throws IOException { | ||
try { | ||
rmPath.getFileSystem().getRmController().setResourceContents( | ||
rmPath.getRmProjectId(), rmPath.getResourcePath(), buf, true | ||
); | ||
} catch (DBException e) { | ||
throw new IOException("Failed to write data to the file: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void deleteFile() throws IOException { | ||
try { | ||
rmPath.getFileSystem().getRmController().deleteResource( | ||
rmPath.getRmProjectId(), rmPath.getResourcePath(), true | ||
); | ||
} catch (DBException e) { | ||
throw new IOException("Failed to delete file: " + e.getMessage(), e); | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/fs/nio/RMNIOFileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.cloudbeaver.model.rm.fs.nio; | ||
|
||
import org.jkiss.code.NotNull; | ||
import org.jkiss.code.Nullable; | ||
import org.jkiss.dbeaver.DBException; | ||
import org.jkiss.dbeaver.Log; | ||
import org.jkiss.dbeaver.model.nio.NIOFileSystem; | ||
import org.jkiss.dbeaver.model.rm.RMController; | ||
import org.jkiss.dbeaver.model.rm.RMProject; | ||
import org.jkiss.dbeaver.model.rm.RMProjectPermission; | ||
import org.jkiss.utils.ArrayUtils; | ||
import org.jkiss.utils.CommonUtils; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.FileStore; | ||
import java.nio.file.Path; | ||
import java.nio.file.spi.FileSystemProvider; | ||
import java.util.List; | ||
|
||
public class RMNIOFileSystem extends NIOFileSystem { | ||
private static final Log log = Log.getLog(RMNIOFileSystem.class); | ||
@Nullable | ||
// null for root 'rm://' path | ||
private final String rmProjectId; | ||
@NotNull | ||
private final RMController rmController; | ||
@NotNull | ||
private final RMNIOFileSystemProvider rmNioFileSystemProvider; | ||
@Nullable | ||
private RMProject rmProject; | ||
|
||
public RMNIOFileSystem( | ||
@Nullable String rmProjectId, | ||
@NotNull RMController rmController, | ||
@NotNull RMNIOFileSystemProvider rmNioFileSystemProvider | ||
) { | ||
this.rmProjectId = rmProjectId; | ||
this.rmController = rmController; | ||
this.rmNioFileSystemProvider = rmNioFileSystemProvider; | ||
} | ||
|
||
@Override | ||
public FileSystemProvider provider() { | ||
return rmNioFileSystemProvider; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly() { | ||
try { | ||
return getRmProject().hasProjectPermission(RMProjectPermission.RESOURCE_EDIT.getPermissionId()); | ||
} catch (IOException e) { | ||
return true; | ||
} | ||
} | ||
|
||
@Override | ||
public Iterable<Path> getRootDirectories() { | ||
return List.of(new RMPath(this)); | ||
} | ||
|
||
@Override | ||
public Iterable<FileStore> getFileStores() { | ||
try { | ||
return List.of(new RMNIOProjectFileStore(getRmProject())); | ||
} catch (IOException e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
return List.of(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Path getPath(@NotNull String first, @NotNull String... more) { | ||
if (CommonUtils.isEmpty(first)) { | ||
throw new IllegalArgumentException("Empty path"); | ||
} | ||
StringBuilder uriBuilder = new StringBuilder(); | ||
uriBuilder.append(provider().getScheme()).append("://"); | ||
if (rmProjectId != null) { | ||
uriBuilder.append(rmProjectId).append(getSeparator()); | ||
|
||
} | ||
uriBuilder.append(first); | ||
if (!ArrayUtils.isEmpty(more)) { | ||
uriBuilder | ||
.append(getSeparator()) | ||
.append(String.join(getSeparator(), more)); | ||
} | ||
return provider().getPath(URI.create(uriBuilder.toString())); | ||
} | ||
|
||
@NotNull | ||
public RMController getRmController() { | ||
return rmController; | ||
} | ||
|
||
@Nullable | ||
public String getRmProjectId() { | ||
return rmProjectId; | ||
} | ||
|
||
@NotNull | ||
public synchronized RMProject getRmProject() throws IOException { | ||
if (rmProject != null) { | ||
return rmProject; | ||
} | ||
if (rmProjectId == null) { | ||
throw new IOException("Project id not specified"); | ||
} | ||
try { | ||
RMProject project = rmController.getProject(rmProjectId, false, false); | ||
if (project == null) { | ||
throw new FileNotFoundException("Project not exist: " + rmProjectId); | ||
} | ||
rmProject = project; | ||
return rmProject; | ||
} catch (DBException e) { | ||
throw new IOException("Failed to get project:" + e.getMessage(), e); | ||
} | ||
} | ||
} |
Oops, something went wrong.