Search in sources :

Example 11 with Path

use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.

the class FileHandler method getString.

@Override
public String getString(JaqyResultSet rs, int column, JaqyInterpreter interpreter) throws Exception {
    Object o = rs.getObject(column);
    if (o == null)
        return null;
    String fileName = m_fileInfo.nameGen.newName();
    Path file = m_csvFile.getRelativePath(fileName);
    if (o instanceof byte[]) {
        FileUtils.writeFile(file, (byte[]) o);
    } else if (o instanceof Blob) {
        Blob blob = (Blob) o;
        InputStream is = ((Blob) o).getBinaryStream();
        FileUtils.writeFile(file, is, interpreter.getByteBuffer());
        is.close();
        blob.free();
    } else if (o instanceof Clob) {
        Clob clob = (Clob) o;
        Reader reader = clob.getCharacterStream();
        FileUtils.writeFile(file, reader, interpreter.getCharBuffer());
        reader.close();
        clob.free();
    } else if (o instanceof SQLXML) {
        SQLXML xml = (SQLXML) o;
        Reader reader = xml.getCharacterStream();
        FileUtils.writeFile(file, m_fileInfo.charset, reader, interpreter.getCharBuffer());
        reader.close();
        xml.free();
    } else {
        FileUtils.writeFile(file, m_fileInfo.charset, o.toString());
    }
    return fileName;
}
Also used : Path(com.teradata.jaqy.interfaces.Path) Blob(java.sql.Blob) SQLXML(java.sql.SQLXML) InputStream(java.io.InputStream) Reader(java.io.Reader) Clob(java.sql.Clob)

Example 12 with Path

use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.

the class CSVImporter method getObject.

@Override
public Object getObject(int index, ParameterInfo paramInfo, JaqyInterpreter interpreter) throws Exception {
    try {
        String value = m_record.get(index);
        if (m_naFilter) {
            for (String f : m_naValues) if (value.equals(f))
                return null;
        }
        CSVImportInfo importInfo = m_importInfoMap.get(index);
        if (importInfo != null) {
            if (value.length() == 0)
                return null;
            Path file = m_file.getRelativePath(value);
            if (!file.isFile())
                throw new FileNotFoundException("External file " + file.getPath() + " is not found.");
            if (importInfo.charset == null)
                return new FileBlob(file);
            else
                return new FileClob(file, importInfo.charset);
        }
        if (TypesUtils.isBinary(paramInfo.type))
            return StringUtils.getBytesFromHexString(value);
        return value;
    } catch (ArrayIndexOutOfBoundsException ex) {
        throw new IOException("Column " + (index + 1) + " is not found.");
    }
}
Also used : Path(com.teradata.jaqy.interfaces.Path) FileBlob(com.teradata.jaqy.resultset.FileBlob) FileClob(com.teradata.jaqy.resultset.FileClob) CSVImportInfo(com.teradata.jaqy.utils.CSVImportInfo)

Aggregations

Path (com.teradata.jaqy.interfaces.Path)12 Test (org.junit.Test)4 Reader (java.io.Reader)3 CommandLine (org.apache.commons.cli.CommandLine)3 Option (org.apache.commons.cli.Option)3 CommandLineInput (com.teradata.jaqy.lineinput.CommandLineInput)2 JLineConsoleLineInput (com.teradata.jaqy.lineinput.JLineConsoleLineInput)2 FilePath (com.teradata.jaqy.path.FilePath)2 Session (com.teradata.jaqy.Session)1 LineInput (com.teradata.jaqy.interfaces.LineInput)1 ReaderLineInput (com.teradata.jaqy.lineinput.ReaderLineInput)1 FileBlob (com.teradata.jaqy.resultset.FileBlob)1 FileClob (com.teradata.jaqy.resultset.FileClob)1 CSVExportInfo (com.teradata.jaqy.utils.CSVExportInfo)1 CSVImportInfo (com.teradata.jaqy.utils.CSVImportInfo)1 CSVNameGen (com.teradata.jaqy.utils.CSVNameGen)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1