use of org.teiid.file.VirtualFileConnection in project teiid by teiid.
the class FileExecutionFactory method createProcedureExecution.
// @Override
public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Connection conn) throws TranslatorException {
if (conn instanceof VirtualFileConnection) {
return new VirtualFileProcedureExecution(command, (VirtualFileConnection) conn);
}
final FileConnection fc = (FileConnection) conn;
if (command.getProcedureName().equalsIgnoreCase(SAVEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
Object file = command.getArguments().get(1).getArgumentValue().getValue();
if (file == null || filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Saving", filePath);
InputStream is = null;
try {
if (file instanceof SQLXML) {
is = ((SQLXML) file).getBinaryStream();
} else if (file instanceof Clob) {
is = new ReaderInputStream(((Clob) file).getCharacterStream(), encoding);
} else if (file instanceof Blob) {
is = ((Blob) file).getBinaryStream();
} else {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("unknown_type"));
}
ObjectConverterUtil.write(is, fc.getFile(filePath));
} catch (IOException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (SQLException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_writing"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
} else if (command.getProcedureName().equalsIgnoreCase(DELETEFILE)) {
return new ProcedureExecution() {
@Override
public void execute() throws TranslatorException {
String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
if (filePath == null) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("non_null"));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Deleting", filePath);
try {
File f = fc.getFile(filePath);
if (!f.exists()) {
if (exceptionIfFileNotFound) {
// $NON-NLS-1$
throw new TranslatorException(DataPlugin.Util.gs("file_not_found", filePath));
}
} else if (!f.delete()) {
// $NON-NLS-1$
throw new TranslatorException(UTIL.getString("error_deleting"));
}
} catch (ResourceException e) {
// $NON-NLS-1$
throw new TranslatorException(e, UTIL.getString("error_deleting"));
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
return null;
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return Collections.emptyList();
}
};
}
return new FileProcedureExecution(command, fc);
}
use of org.teiid.file.VirtualFileConnection in project teiid by teiid.
the class TestFtpFileConnection method testRemove.
@Test
public void testRemove() throws ResourceException, IOException {
VirtualFileConnection conn = sample();
// $NON-NLS-1$
VirtualFile pom = VFS.getChild(new File("pom.xml").getAbsolutePath());
// $NON-NLS-1$
VirtualFile file = conn.getFile("pom.xml");
conn.add(pom.openStream(), pom);
assertTrue(file.exists());
// $NON-NLS-1$
conn.remove("pom.xml");
assertFalse(file.exists());
conn.close();
}
use of org.teiid.file.VirtualFileConnection in project teiid by teiid.
the class TestFtpFileConnection method testAdd.
@Test
public void testAdd() throws IOException, ResourceException {
VirtualFileConnection conn = sample();
// $NON-NLS-1$
VirtualFile file = conn.getFile("pom.xml");
assertFalse(file.exists());
// $NON-NLS-1$
VirtualFile pom = VFS.getChild(new File("pom.xml").getAbsolutePath());
conn.add(pom.openStream(), pom);
assertTrue(file.exists());
conn.close();
conn = sample();
assertTrue(file.isFile());
assertNotNull(file.openStream());
conn.close();
}
use of org.teiid.file.VirtualFileConnection in project teiid by teiid.
the class TestFtpFileConnection method testGetFile.
@Test
public void testGetFile() throws ResourceException, IOException {
VirtualFileConnection conn = sample();
// $NON-NLS-1$
VirtualFile file = conn.getFile("marketdata-price.txt");
assertNotNull(file.openStream());
// $NON-NLS-1$
file = conn.getFile("marketdata-price1.txt");
assertNotNull(file.openStream());
conn.close();
}
use of org.teiid.file.VirtualFileConnection in project teiid by teiid.
the class TestFtpFileConnection method testGetFiles.
@Test(expected = ResourceException.class)
public void testGetFiles() throws ResourceException, IOException {
VirtualFileConnection conn = sample();
VirtualFile[] files = conn.getFiles("*.txt");
// $NON-NLS-1$
assertEquals(2, files.length);
conn.close();
}
Aggregations