@Override public Clob createSerial(Clob clob) throws SQLException { return new SerialClob(clob); } }
/** * Create a new Clob. * @param text The null value is supported. */ public static final SerialClob createClob(char[] text) { try { return text!=null ? new SerialClob(text) : null; } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public void executeSetPreparedStatement(Object pstmt, int index, Object data) throws Exception { if (data == null || ((String) data).length() == 0) { ((PreparedStatement) pstmt).setNull(index, Types.CLOB); } else { ((PreparedStatement) pstmt).setClob(index, new SerialClob(((String) data).toCharArray())); } }
@Override public Clob getClob(final int columnIndex) throws SQLException { final String s = getString(columnIndex); if (s == null) { return null; } return new SerialClob(s.toCharArray()); }
public Clob convert(String obj) throws ConversionException { try { return new javax.sql.rowset.serial.SerialClob(obj.toCharArray()); } catch (Exception e) { throw new ConversionException(e); } } }
/** * Create a new Clob. * @param text The null value is supported. */ public static final SerialClob createClob(char[] text) { try { return text!=null ? new SerialClob(text) : null; } catch (Exception e) { throw new IllegalUjormException(e); } }
/** * {@inheritDoc} */ public Object convert(String value, TypeLiteral<?> toType) { try { return new SerialClob(value.toCharArray()); } catch (Exception e) { throw new ProvisionException("String value '" + value + "' is not a valid InetAddress", e); } }
@Override public NClob createSerial(NClob clob) throws SQLException { return Proxies.createProxy(NClob.class, new SimpleInvocationHandler(new SerialClob(clob))); } }
public Clob getClob(int columnIndex) throws SQLException { preAccessor(columnIndex); if (isNull(columnIndex)) { return null; } return new SerialClob(getString(columnIndex).toCharArray()); }
@Test(expected=FunctionExecutionException.class) public void testToBytes3() throws Exception { helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("a".toCharArray())), "BASE64" }, null); //$NON-NLS-1$ }
@Test public void testClobCompare() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType ct = new ClobType(clob); SerialClob clob1 = new SerialClob(testString.toCharArray()); ClobType ct1 = new ClobType(clob1); assertEquals(0, ct1.compareTo(ct)); }
@Test public void testClobToStringConversion() throws Exception { Clob clob = new SerialClob("foo".toCharArray()); //$NON-NLS-1$ String value = DataTypeTransformer.getString(clob); assertEquals("foo", value); //$NON-NLS-1$ }
@Test public void testToBytes4() throws Exception { Blob result = (Blob)helpInvokeMethod("to_bytes", new Class<?>[] {DefaultDataClasses.CLOB, DefaultDataClasses.STRING}, new Object[] { new ClobType(new SerialClob("hello world 平仮名".toCharArray())), "utf_8_BOM" }, null); //$NON-NLS-1$ byte[] bytes = ObjectConverterUtil.convertToByteArray(result.getBinaryStream()); assertEquals(bytes[0], (byte)0xef); assertEquals(bytes[1], (byte)0xbb); assertEquals(bytes[2], (byte)0xbf); assertEquals("hello world 平仮名", new String(bytes, "UTF-8")); }
@Test(expected=TeiidProcessingException.class) public void testTextTableInvalidData() throws Exception { String sql = "select count(*) from texttable(? COLUMNS PARTNAME string) x"; //$NON-NLS-1$ FakeDataManager dataManager = new FakeDataManager(); sampleData1(dataManager); char[] data = new char[5000]; processPreparedStatement(sql, null, dataManager, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), Arrays.asList(new ClobType(new SerialClob(data)))); }
@Test public void testClobValue() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType cv = new ClobType(clob); assertEquals(testString, cv.getSubString(1L, (int)cv.length())); }
@Test public void testClobHashError() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); clob.free(); ClobType ct = new ClobType(clob); assertEquals(0, ct.hashCode()); }
@Test public void testLobHandling() throws Exception { ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ x.setType(DataTypeManager.DefaultDataClasses.CLOB); List<ElementSymbol> schema = Arrays.asList(x); TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tb.setInlineLobs(false); ClobType c = new ClobType(new SerialClob(new char[0])); TupleBatch batch = new TupleBatch(1, new List[] {Arrays.asList(c)}); tb.addTupleBatch(batch, false); assertNotNull(tb.getLobReference(c.getReferenceStreamId())); }
@Test public void testReferencePersistence() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType cv = new ClobType(clob); cv.setReferenceStreamId(null); // now force to serialize ClobType read = UnitTestUtil.helpSerialize(cv); assertTrue(read.length() > 0); assertEquals(testString, read.getSubString(1, testString.length())); }
private void helpTestJson(String json, String rootName, String expected) throws SQLException, TeiidComponentException, TeiidProcessingException, SerialException, IOException { CommandContext cc = new CommandContext(); cc.setBufferManager(BufferManagerFactory.getStandaloneBufferManager()); SQLXML xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialClob(json.toCharArray())); assertEquals(expected, xml.getString()); xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-8")))); assertEquals(expected, xml.getString()); xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-32BE")))); assertEquals(expected, xml.getString()); }
@Test public void testClobValuePersistence() throws Exception { String testString = "this is test clob"; //$NON-NLS-1$ SerialClob clob = new SerialClob(testString.toCharArray()); ClobType cv = new ClobType(clob); String key = cv.getReferenceStreamId(); // now force to serialize ClobType read = UnitTestUtil.helpSerialize(cv); assertTrue(read.length() > 0); // make sure we have kept the reference stream id assertEquals(key, read.getReferenceStreamId()); // and lost the original object assertNull(read.getReference()); }