Search in sources :

Example 36 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestFunctionLibrary method testToBytes.

@Test
public void testToBytes() throws Exception {
    // $NON-NLS-1$
    Blob result = (Blob) helpInvokeMethod("to_bytes", new Class<?>[] { DefaultDataClasses.CLOB, DefaultDataClasses.STRING }, new Object[] { new ClobType(new SerialClob("hello world".toCharArray())), "UTF32" }, null);
    // 4 bytes / char
    assertEquals(44, result.length());
}
Also used : ClobType(org.teiid.core.types.ClobType) SerialBlob(javax.sql.rowset.serial.SerialBlob) Blob(java.sql.Blob) SerialClob(javax.sql.rowset.serial.SerialClob) Test(org.junit.Test)

Example 37 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestFunctionLibrary method testInvokeXslTransform.

@Test
public void testInvokeXslTransform() throws Exception {
    CommandContext c = new CommandContext();
    c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
    ClobType result = (ClobType) helpInvokeMethod("xsltransform", new Class<?>[] { DataTypeManager.DefaultDataClasses.XML, DataTypeManager.DefaultDataClasses.XML }, new Object[] { DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>", DataTypeManager.DefaultDataClasses.XML), DataTypeManager.transformValue("<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template><xsl:template match=\"Quantity\"/></xsl:stylesheet>", DataTypeManager.DefaultDataClasses.XML) }, c);
    String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml);
}
Also used : ClobType(org.teiid.core.types.ClobType) CommandContext(org.teiid.query.util.CommandContext) Test(org.junit.Test)

Example 38 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class TestFunctionMethods method regexpReplaceOkay.

@Test
public void regexpReplaceOkay() throws Exception {
    assertEquals("fooXbaz", FunctionMethods.regexpReplace(null, "foobarbaz", "b..", "X"));
    assertEquals("fooXX", FunctionMethods.regexpReplace(null, "foobarbaz", "b..", "X", "g"));
    assertEquals("fooXarYXazY", FunctionMethods.regexpReplace(null, "foobarbaz", "b(..)", "X$1Y", "g"));
    assertEquals("fooBXRbXz", FunctionMethods.regexpReplace(null, "fooBARbaz", "a", "X", "gi"));
    assertEquals("xxbye Wxx", FunctionMethods.regexpReplace(TestProcessor.createCommandContext(), "Goodbye World", "[g-o].", "x", "gi"));
    assertEquals(new ClobType(new ClobImpl("xxbye Wxx")), FunctionMethods.regexpReplace(TestProcessor.createCommandContext(), new ClobType(new ClobImpl("Goodbye World")), "[g-o].", "x", "gi"));
}
Also used : ClobType(org.teiid.core.types.ClobType) ClobImpl(org.teiid.core.types.ClobImpl) Test(org.junit.Test)

Example 39 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class ResultSetImpl method getObjectDirect.

/**
 * Get the value of the current row at the column index specified.
 * @param column Column index
 * @return Value at column, which may be null
 * @throws SQLException if this result set has an exception
 */
public Object getObjectDirect(int column) throws SQLException {
    checkClosed();
    if (column < 1 || column > columnCount) {
        // $NON-NLS-1$
        throw new IllegalArgumentException(JDBCPlugin.Util.getString("ResultsImpl.Invalid_col_index", column));
    }
    List<?> cursorRow = batchResults.getCurrentRow();
    if (cursorRow == null) {
        // $NON-NLS-1$
        throw new TeiidSQLException(JDBCPlugin.Util.getString("ResultsImpl.The_cursor_is_not_on_a_valid_row._1"));
    }
    // defect 13539 - set the currentValue (defined in MMResultSet) so that wasNull() accurately returns whether this value was null
    currentValue = cursorRow.get(column - 1);
    if (currentValue instanceof Streamable<?>) {
        Object reference = ((Streamable<?>) currentValue).getReference();
        if (reference != null) {
            return reference;
        }
        if (currentValue instanceof ClobType) {
            return new ClobImpl(createInputStreamFactory((ClobType) currentValue), ((ClobType) currentValue).getLength());
        } else if (currentValue instanceof BlobType) {
            InputStreamFactory isf = createInputStreamFactory((BlobType) currentValue);
            isf.setLength(((BlobType) currentValue).getLength());
            return new BlobImpl(isf);
        } else if (currentValue instanceof XMLType) {
            XMLType val = (XMLType) currentValue;
            SQLXMLImpl impl = new SQLXMLImpl(createInputStreamFactory(val));
            impl.setEncoding(val.getEncoding());
            return impl;
        }
    } else if (currentValue instanceof java.util.Date) {
        return TimestampWithTimezone.create((java.util.Date) currentValue, serverTimeZone, getDefaultCalendar(), currentValue.getClass());
    } else if (maxFieldSize > 0 && currentValue instanceof String) {
        String val = (String) currentValue;
        return val.substring(0, Math.min(maxFieldSize / 2, val.length()));
    } else if (currentValue instanceof BinaryType) {
        BinaryType val = (BinaryType) currentValue;
        return val.getBytesDirect();
    }
    return currentValue;
}
Also used : SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) BinaryType(org.teiid.core.types.BinaryType) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) XMLType(org.teiid.core.types.XMLType) BlobType(org.teiid.core.types.BlobType) Streamable(org.teiid.core.types.Streamable) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl)

Example 40 with ClobType

use of org.teiid.core.types.ClobType in project teiid by teiid.

the class CouchbaseExecutionFactory method retrieveValue.

public Object retrieveValue(Class<?> columnType, Object value) throws TranslatorException {
    if (value == null) {
        return null;
    }
    if (value.getClass().equals(columnType)) {
        return value;
    }
    if (columnType.equals(ClobType.class)) {
        boolean json = false;
        if (value instanceof JsonValue) {
            json = true;
        }
        ClobImpl clob = new ClobImpl(value.toString());
        ClobType result = new ClobType(clob);
        result.setType(json ? Type.JSON : Type.TEXT);
        return result;
    }
    if (columnType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        }
        return BigInteger.valueOf(((Number) value).longValue());
    }
    if (columnType.equals(BigDecimal.class)) {
        if (value instanceof BigInteger) {
            value = new BigDecimal((BigInteger) value);
        } else {
            value = BigDecimal.valueOf(((Number) value).doubleValue());
        }
    }
    return value;
}
Also used : ClobType(org.teiid.core.types.ClobType) JsonValue(com.couchbase.client.java.document.json.JsonValue) BigInteger(java.math.BigInteger) ClobImpl(org.teiid.core.types.ClobImpl) BigDecimal(java.math.BigDecimal)

Aggregations

ClobType (org.teiid.core.types.ClobType)49 Test (org.junit.Test)31 ClobImpl (org.teiid.core.types.ClobImpl)20 Expression (org.teiid.query.sql.symbol.Expression)16 SQLException (java.sql.SQLException)8 InputStreamFactory (org.teiid.core.types.InputStreamFactory)8 IOException (java.io.IOException)7 BlobType (org.teiid.core.types.BlobType)6 Reader (java.io.Reader)4 Blob (java.sql.Blob)4 ArrayList (java.util.ArrayList)4 SerialBlob (javax.sql.rowset.serial.SerialBlob)4 SerialClob (javax.sql.rowset.serial.SerialClob)4 BlobImpl (org.teiid.core.types.BlobImpl)4 XMLType (org.teiid.core.types.XMLType)4 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 BlobInputStreamFactory (org.teiid.core.types.InputStreamFactory.BlobInputStreamFactory)3 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)3 ReaderInputStream (org.teiid.core.util.ReaderInputStream)3