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());
}
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);
}
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"));
}
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;
}
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;
}
Aggregations