Search in sources :

Example 26 with ClobImpl

use of org.teiid.core.types.ClobImpl 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)

Example 27 with ClobImpl

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

the class ODataSQLBuilder method updateStreamProperty.

public Update updateStreamProperty(EdmProperty edmProperty, final InputStream content) throws TeiidException {
    Update update = new Update();
    update.setGroup(this.context.getGroupSymbol());
    Column column = this.context.getColumnByName(edmProperty.getName());
    ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
    update.addChange(symbol, new Reference(0));
    Class<?> lobType = DataTypeManager.getDataTypeClass(column.getRuntimeType());
    int sqlType = JDBCSQLTypeInfo.getSQLType(column.getRuntimeType());
    if (content == null) {
        this.params.add(new SQLParameter(null, sqlType));
    } else {
        Object value = null;
        InputStreamFactory isf = new InputStreamFactory() {

            @Override
            public InputStream getInputStream() throws IOException {
                return content;
            }
        };
        if (lobType.isAssignableFrom(SQLXML.class)) {
            value = new SQLXMLImpl(isf);
        } else if (lobType.isAssignableFrom(ClobType.class)) {
            value = new ClobImpl(isf, -1);
        } else if (lobType.isAssignableFrom(BlobType.class)) {
            value = new BlobImpl(isf);
        } else {
            throw new TeiidException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16031, column.getName()));
        }
        this.params.add(new SQLParameter(value, sqlType));
    }
    update.setCriteria(this.context.getCriteria());
    return update;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) Reference(org.teiid.query.sql.symbol.Reference) SQLParameter(org.teiid.odata.api.SQLParameter) InputStreamFactory(org.teiid.core.types.InputStreamFactory) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidException(org.teiid.core.TeiidException) ClobType(org.teiid.core.types.ClobType) Column(org.teiid.metadata.Column) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl)

Example 28 with ClobImpl

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

the class TestJDBCSocketTransport method testGeometryStreaming.

@Test
public void testGeometryStreaming() throws Exception {
    StringBuilder geomString = new StringBuilder();
    for (int i = 0; i < 600; i++) {
        geomString.append("100 100,");
    }
    geomString.append("100 100");
    final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((" + geomString + "))")));
    long length = geo.length();
    PreparedStatement s = conn.prepareStatement("select st_geomfrombinary(?)");
    s.setBlob(1, new BlobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            try {
                return geo.getBinaryStream();
            } catch (SQLException e) {
                throw new IOException(e);
            }
        }
    }));
    ResultSet rs = s.executeQuery();
    rs.next();
    Blob b = rs.getBlob(1);
    assertEquals(length, b.length());
    b.getBytes(1, (int) b.length());
    toggleInline(false);
    rs = s.executeQuery();
    rs.next();
    b = rs.getBlob(1);
    assertEquals(length, b.length());
    b.getBytes(1, (int) b.length());
}
Also used : Blob(java.sql.Blob) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) GeometryType(org.teiid.core.types.GeometryType) ResultSet(java.sql.ResultSet) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl) Test(org.junit.Test)

Aggregations

ClobImpl (org.teiid.core.types.ClobImpl)28 ClobType (org.teiid.core.types.ClobType)21 InputStreamFactory (org.teiid.core.types.InputStreamFactory)14 IOException (java.io.IOException)10 Test (org.junit.Test)10 BlobImpl (org.teiid.core.types.BlobImpl)8 SQLException (java.sql.SQLException)7 BlobType (org.teiid.core.types.BlobType)6 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)6 Blob (java.sql.Blob)5 List (java.util.List)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Reader (java.io.Reader)3 BigInteger (java.math.BigInteger)3 Clob (java.sql.Clob)3 SQLXML (java.sql.SQLXML)3 HashMap (java.util.HashMap)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3